链接:https://www.nowcoder.com/acm/contest/104/A来源:牛客网
A. Srdce and Triangle
空间限制:C/C++ 32768K,其他语言65536K
Special Judge, 64bit IO Format: %lld
题目描述
输入描述:
Input contains multiple cases, please process to the end of input.
For each line in the input, contains three integers, $alpha, eta, gamma$, which are the size of the angel , and in degree.
输出描述:
For each line of input, output one line with three numbers in ascending order, the three angles in the new triangle, your answer will be considered as correct if and only if the relative or absolute error is less than
, If the new triangle cannot be formed, output -1 -1 -1 instead.
输入
120 120 120
输出
60.0000 60.0000 60.0000
做一个等边三角形,然后全等
#include<bits/stdc++.h> using namespace std; int main() { int a[4]; while(~scanf("%d%d%d",&a[0],&a[1],&a[2])) { sort(a,a+3); if(a[0]<=60||a[2]>=180||a[0]+a[1]+a[2]!=360) printf("-1 -1 -1 "); else printf("%.4f %.4f %.4f ",a[0]-60.,a[1]-60.,a[2]-60.); } }
链接:https://www.nowcoder.com/acm/contest/104/C
来源:牛客网
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld
题目描述
Who killed Cock Robin?
I, said the Sparrow, With my bow and arrow,I killed Cock Robin.
Who saw him die?
I, said the Fly.With my little eye,I saw him die.
Who caught his blood?
I, said the Fish,With my little dish,I caught his blood.
Who'll make his shroud?
I, said the Beetle,With my thread and needle,I'll make the shroud.
.........
All the birds of the air
Fell a-sighing and a-sobbing.
When they heard the bell toll.
For poor Cock Robin.
March 26, 2018
Sparrows are a kind of gregarious animals,sometimes the relationship between them can be represented by a tree.
The Sparrow is for trial, at next bird assizes,we should select a connected subgraph from the whole tree of sparrows as trial objects.
Because the relationship between sparrows is too complex, so we want to leave this problem to you. And your task is to calculate how many different ways can we select a connected subgraph from the whole tree.
输入描述:
The first line has a number n to indicate the number of sparrows.
The next n-1 row has two numbers x and y per row, which means there is an undirected edge between x and y.
输出描述:
The output is only one integer, the answer module 10000007 (107+7) in a line
输入
4 1 2 2 3 3 4
输出
10
说明
For a chain, there are ten different connected subgraphs:
需要想到用乘法原理啊啊,真是太傻了
#include<bits/stdc++.h> using namespace std; const int N=2e5+5,MD=1e7+7; typedef long long ll; vector<int>G[N]; int ans,n; int dfs(int u,int fa) { ll t=1; for(auto v:G[u]) { if(fa==v)continue; t=t*(dfs(v,u)+1)%MD; } ans=(ans+t)%MD; return t; } int main() { scanf("%d",&n); for(int i=1,x,y; i<n; i++) scanf("%d%d",&x,&y),G[x].push_back(y),G[y].push_back(x); dfs(1,0); printf("%d ",ans); return 0; }
链接:https://www.nowcoder.com/acm/contest/104/E
来源:牛客网
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld
题目描述
Once upon a time, there was a beautiful princess named TQM, and a handsome prince named GSS. One day, the prince would like to visit the princess. While in front of the princess' house, there was a flower-beds with blooming flowers. The prince was supposed to go through the flower-beds choosing the best ``Flower Road''.
Here is the task. The flower-beds is presented by a matrix with integers on each grid representing the princess' satisfaction of the flowers on it. Now, the prince was on the top left point (1, 1) and the princess was on the bottom right point (N, N). While the princess didn't want this to be so easy, she operated M times ``rotation'' on the flower-beds according to the order. Each time, she would choose a matrix whose top left point was . Then, four disjoint parts of the matrix whose length of size was rotated clockwise. Here is an example to make the ``rotation'' clearly.
Then, your task is to help the prince to choose a best ``Flower Road'' after these operations with the largest sum of the satisfaction. By the way, the prince will take the shortest way, which means he will only go down (from point (x, y) to point (x+1, y)) and right (from point (x, y) to point (x, y+1)).
输入描述:
The first line of input contains two integers, N (
) and M (
), indicating the numbers N and M described above. Then N lines follow, and each line N integers, representing the matrix. Then M lines follow, each line has three integers
, where xi
and yi
are coordinates of the top right point of i-th rotation matrix,
th - side length of the matrix.
输出描述:
Output the max sum of the satisfaction.
输入
4 1 1 2 5 6 3 4 7 8 13 14 9 10 15 16 11 12 1 1 2
输出
81
经过m次旋转操作然后求下1,1到n,n的最短路
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=1505; int a[N][N],n; ll dp[N][N]; ll DP() { for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) dp[i][j]=max(dp[i][j],max(dp[i-1][j]+a[i][j],dp[i][j-1]+a[i][j])); return dp[n][n]; } int main() { ios::sync_with_stdio(false),cin.tie(0); int m; cin>>n>>m; for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) cin>>a[i][j]; while(m--) { int xi,yi,li; cin>>xi>>yi>>li; for(int i=0; i<li; i++) for(int j=0; j<li; j++) { int t=a[xi+i][yi+j]; a[xi+i][yi+j]=a[xi+li+i][yi+j]; a[xi+li+i][yi+j]=a[xi+li+i][yi+li+j]; a[xi+li+i][yi+li+j]=a[xi+i][yi+j+li]; a[xi+i][yi+j+li]=t; } } cout<<DP(); return 0; }
链接:https://www.nowcoder.com/acm/contest/104/G
来源:牛客网
空间限制:C/C++ 32768K,其他语言65536K
64bit IO Format: %lld
题目描述
输入描述:
输出描述:
Output one line with the answer
输入
5 11 12 13 14 15
输出
360360
大数签到题目
java可以,py也可以,但是不推荐py,因为比赛还不支持
import java.math.*; import java.util.*; public class Main { static public void main(String[] args) { Scanner cin=new Scanner(System.in); while(cin.hasNext()) { int n = cin.nextInt(); BigInteger mul = BigInteger.ONE; for(int i = 1; i <= n; i++) { BigInteger x = cin.nextBigInteger(); mul = mul.multiply(x); } System.out.println(mul); } } }
py的
t=input() s=1 for i in range(t): s=s*input() print s
链接:https://www.nowcoder.com/acm/contest/104/H
来源:牛客网
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld
题目描述
Mingming, a cute girl of ACM/ICPC team of Wuhan University, is alone since graduate from high school. Last year, she used a program to match boys and girls who took part in an active called Boy or Girl friend in five days.
She numbered n () boys from 1 to (n), by their date of birth, and given i-th boy a number () in almost random. (We do not mean that in your input is generated in random.). Then she numbered m () girls from 1 to m, and given i-th girl a number () in the same way.
Also, i-th girl said that she only wanted to be matched to a boy whose age is between , which means that she should only be matched to a boy numbered from , ().
Mingming defined a rate R(i,j) to measure the score when the i-th boy and j-th girl matched. Where where means bitwise exclusive or. The higher, the better.
Now, for every girl, Mingming wants to know the best matched boy, or her "Mr. Right" can be found while her . As this is the first stage of matching process and Mingming will change the result manually, two girls can have the same "Mr. Right".
输入描述:
The first line contains one number n.
The second line contains n integers, the i-th one is .
The third line contains an integer m.
Then followed by m lines, the j-th line contains three integers .
输出描述:
Output m lines, the i-th line contains one integer, which is the matching rate of i-th girl and her Mr. Right.
输入
4 19 19 8 10 2 1 1 4 5 1 4
输出
18 22
01trie去找这个最大值
#include<bits/stdc++.h> using namespace std; const int N=1e5+5; int rt[N],tot,cnt[N*40],ls[N*40],rs[N*40]; void ins(int x,int d,int ln,int &rn) { rn=++tot; cnt[rn]=cnt[ln]+1,ls[rn]=ls[ln],rs[rn]=rs[ln]; if(d<0)return; if(~x>>d&1)ins(x,d-1,ls[ln],ls[rn]); else ins(x,d-1,rs[ln],rs[rn]); } int query(int x,int d,int ln,int rn) { if(d<0)return 0; if(~x>>d&1) { if(cnt[rs[rn]]>cnt[rs[ln]])return (1<<d)+query(x,d-1,rs[ln],rs[rn]); return query(x,d-1,ls[ln],ls[rn]); } else { if(cnt[ls[rn]]>cnt[ls[ln]])return (1<<d)+query(x,d-1,ls[ln],ls[rn]); return query(x,d-1,rs[ln],rs[rn]); } } int main() { int n,m; scanf("%d",&n); for(int i=0,x;i<n;i++) scanf("%d",&x),ins(x,29,rt[i],rt[i+1]); scanf("%d",&m); for(int i=0,b,l,r;i<m;i++) scanf("%d%d%d",&b,&l,&r),printf("%d ",query(b,29,rt[l-1],rt[r])); return 0; }