Description
Diao Ze likes math very much, especially problems about equation. Now there is a problem for Diao Ze, but he is too lazy to solve it and he asks you for help:
Giving two integers a and b , which satisfied the equation
Then your task is to calculate the value of x in the equation.
Input
The first line contains an integer T , indicating the total number of test cases. In each test case there is only one line contains two positive integers and
Output
For each test case, output the answer in one line. The answer should be rounded to 2 digits after the decimal point.
Sample Input
2 1 2 3 2
Sample Output
2.00 0.67
1 #include<stdio.h> 2 //#include<bits/stdc++.h> 3 #include<string.h> 4 #include<iostream> 5 #include<math.h> 6 #include<sstream> 7 #include<set> 8 #include<queue> 9 #include<map> 10 #include<vector> 11 #include<algorithm> 12 #include<limits.h> 13 #define inf 0x7fffffff 14 #define INFL 0x7fffffffffffffff 15 #define lson l,m,rt<<1 16 #define rson m+1,r,rt<<1|1 17 #define LL long long 18 #define ULL unsigned long long 19 using namespace std; 20 int main() 21 { 22 int t; 23 while(cin>>t) 24 { 25 while(t--) 26 { 27 double a,b; 28 cin>>a>>b; 29 printf("%.2f ",b/a); 30 } 31 } 32 return 0; 33 }
Description
After the 40th ACM-ICPC, Diao Yang is thinking about finding a girlfriend because he feels very lonely when doing ACM all the time. But because of his philandering, he finally decided to find N girlfriends. To achieve his goal, he wanted to find one girlfriend every day for N days continue. That is to say, at the ith day, he will have i girlfriends exactly.
In order to make his N girlfriends happy, he decided to buy M candies everyday for N days continue. Every day all of his girlfriends can get candies, and he will give each of them the same amount of candies and the amount will be as much as possible. Then if there are some candies left, he will eat them by himself.
Now the problem is, Diao Yang want to know how many candies he can eat total by himself after N days continue.
Input
The first line contains an integer T, indicating the total number of test cases. Each test case is a line with two integers N and M
Output
For each test case, output the answer in one line.
Sample Input
2 5 7 6 4
Sample Output
7 9
我们看一看20%i(i从1到20)是什么情况
0 0 2 0 0 2 6 4 2 0 9 8 7 6 5 4 3 2 1 0(模)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20(i)
20106 5 4 3 2 2 2 2 1 1 1 1 1 1 1 1 1 1(20/i)
如果i大于M呢。。6 4这样
0 0 1 0 4 4(多出的部分是本身)那么我们只要考虑不超过的部分就好了
超过的就是ans+=(n-m)*m
知道是等差数列,要求和需要公差和它的长度,好吧,公差是D=m/i
现在求长度了和首项了
长度的话就是
min((m%i)/d+1,min(n,m)-i+1);
首项就是m%i
长度的解释,一种是首项/公差+1,或者是像
9 8 7 6 5 4 3 2 1 0这种的
找完一个数列之后,我们跳到下一个数列
就是i+=数列长度-1
1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 using namespace std; 5 int main() 6 { 7 long long t; 8 scanf("%lld",&t); 9 while(t--) 10 { 11 long long ans=0; 12 long long a,b; 13 long long i; 14 scanf("%lld%lld",&a,&b); 15 long long MIN=min(a,b); 16 ans+=max(a-b,0LL)*b; 17 for(i=2; i<=MIN; i++) 18 { 19 if(b%i!=0) 20 { 21 long long d=b/i; 22 long long L=min((b%i)/d+1,MIN-i+1); 23 ans+=(b%i)*L+((L-1)*L/2)*(-1*d); 24 i+=L-1; 25 // cout<<ans<<endl; 26 // d=0; 27 } 28 } 29 printf("%lld ",ans); 30 } 31 return 0; 32 }
Description
As everyone knows, Mine Sweeping is a very famous computer game. When Diao Fei was young, he also liked to play this game very much. A sample of situation when win the game is like this below:
In a situation of winning this game, there are three kinds of grid:
·number grid:the grid has a number in it.Like
·blank grid:the grid has nothing in it. Like
·mine grid:the grid has a mine in it. Like
The game’s rule is that, if a grid is a number grid and it has an number x in it, the eight grids (up, down, left, right, up-left, up-right, down-left, down-right, if exists) which around it should have excatly x mine grids in total. If a grid is a blank grid, then any grid around it should not be a mine grid.
Now the problem is, in a situation of winning this game, giving all of the mine grids, your task is to determine what kind the remain grids are.
Input
The first line contains an integer T, indicating the total number of test cases.
In each test case, the first line is three integers N, M, K() indicating the game size is N rows (numbered from 1 to N) and M columns (numbered from 1 to M), and there are K mines in total. Then K lines follow, each line contains two integersx, y(
,
) indicating the grid in xth row and yth column is a mine grid. You can assume that there are not any two mine grids in the same position.
Output
For each test case, output N lines, each line contain M characters, the jth character in the ith line indicates the grid in the ith row and the jth column. If the grid is a number grid, output the number in the grid. If the grid is a blank grid, output the character ‘.’ (without quotes). If the grid is a mine grid, output the character ‘M’ (without quotes). Notice that after each test case, you should output a blank line at the end.
Sample Input
2 9 9 10 1 1 2 1 2 6 3 3 5 9 6 3 6 8 6 9 7 6 8 2 5 5 1 3 3
Sample Output
M2..111.. M3111M1.. 12M1111.. .111...11 .111..13M .1M1112MM 12211M222 1M1.111.. 111...... ..... .111. .1M1. .111. .....
1 #include<stdio.h> 2 //#include<bits/stdc++.h> 3 #include<string.h> 4 #include<iostream> 5 #include<math.h> 6 #include<sstream> 7 #include<set> 8 #include<queue> 9 #include<map> 10 #include<vector> 11 #include<algorithm> 12 #include<limits.h> 13 #define inf 0x7fffffff 14 #define INFL 0x7fffffffffffffff 15 #define lson l,m,rt<<1 16 #define rson m+1,r,rt<<1|1 17 #define LL long long 18 #define ULL unsigned long long 19 using namespace std; 20 char mp[100][100]; 21 int main() 22 { 23 int t; 24 cin>>t; 25 while(t--) 26 { 27 int n,m,num; 28 int x,y; 29 cin>>n>>m>>num; 30 for(int i=0;i<=n+1;i++) 31 { 32 for(int j=0;j<=m+1;j++) 33 { 34 mp[i][j]='.'; 35 } 36 } 37 for(int i=1; i<=num; i++) 38 { 39 cin>>x>>y; 40 mp[x][y]='M'; 41 if(mp[x-1][y]=='x') 42 { 43 mp[x-1][y]='N'; 44 } 45 if(mp[x][y-1]=='x') 46 { 47 mp[x][y-1]='N'; 48 } 49 if(mp[x+1][y]=='x') 50 { 51 mp[x+1][y]='N'; 52 } 53 if(mp[x][y+1]=='x') 54 { 55 mp[x][y+1]='N'; 56 } 57 if(mp[x-1][y-1]=='x') 58 { 59 mp[x-1][y-1]='N'; 60 } 61 if(mp[x-1][y+1]=='x') 62 { 63 mp[x-1][y+1]='N'; 64 } 65 if(mp[x+1][y-1]=='x') 66 { 67 mp[x+1][y-1]='N'; 68 } 69 if(mp[x+1][y+1]=='x') 70 { 71 mp[x+1][y+1]='N'; 72 } 73 } 74 for(int i=1; i<=n; i++) 75 { 76 for(int j=1; j<=m; j++) 77 { 78 if(mp[i][j]=='.') 79 { 80 int ans=0; 81 for(int s=i-1;s<=i+1;s++) 82 { 83 for(int c=j-1;c<=j+1;c++) 84 { 85 if(mp[s][c]=='M') 86 { 87 ans++; 88 } 89 } 90 } 91 if(ans) 92 { 93 mp[i][j]=ans+'0'; 94 } 95 } 96 // cout<<mp[i][j]; 97 } 98 // cout<<endl; 99 } 100 for(int i=1; i<=n; i++) 101 { 102 for(int j=1; j<=m; j++) 103 { 104 cout<<mp[i][j]; 105 } 106 cout<<endl; 107 } 108 cout<<endl; 109 } 110 return 0; 111 }
Description
Now it is well-known that after the 40th ACM/ICPC, Diao Yang has found many girlfriends, and Diao Yang will buy much candies for them every day. But today, Diao Yang has no much money to buy any candies for his girlfriends. Because Diao Yang is always very nice to his girlfriends, these pretty girls decided to buy some chocolates for him today as return.
Then Girls went to a supermarket and chose many different chocolates. In order to distinguish these chocolates, they marked them by numbers. Any two chocolates chosen by the same girl were marked by the same number, and any two chocolates chosen by different girls were marked by different numbers. Then girls went back home, put their chocolates in a line on the table and gave Diao Yang to eat. But before Diao Yang ate, the girls gave him a problem: can you find the distance of the nearest two chocolates which were marked by the same girl? As Diao Yang is too hungry to solve this problem, he asks you for help.
Input
The first line contains an integer T indicating the total number of test cases.
In each test case, there are two lines. The first line is an integer n(), indicating there are n chocolates. The second line contains n integers, indicating the marked number for each chocolate. All the integers will be no more than 100.
Output
For each test case, output the answer in one line. You can assume that there are at least two chocolates which were marked by the same girl.
Sample Input
2 8 2 3 8 1 5 3 4 5 6 2 3 2 1 3 1
Sample Output
3 2
数据量小,我们暴力就好~
1 #include<stdio.h> 2 //#include<bits/stdc++.h> 3 #include<string.h> 4 #include<iostream> 5 #include<math.h> 6 #include<sstream> 7 #include<set> 8 #include<queue> 9 #include<map> 10 #include<vector> 11 #include<algorithm> 12 #include<limits.h> 13 #define inf 0x7fffffff 14 #define INFL 0x7fffffffffffffff 15 #define lson l,m,rt<<1 16 #define rson m+1,r,rt<<1|1 17 #define LL long long 18 #define ULL unsigned long long 19 using namespace std; 20 int main() 21 { 22 23 int t; 24 while(cin>>t) 25 { 26 while(t--) 27 { 28 int n; 29 int b=10000; 30 int a[1000]; 31 cin>>n; 32 for(int i=0;i<n;i++) 33 { 34 cin>>a[i]; 35 } 36 for(int i=0;i<n;i++) 37 { 38 for(int j=i+1;j<n;j++) 39 { 40 if(a[i]==a[j]) 41 { 42 b=min(b,j-i); 43 } 44 } 45 } 46 cout<<b<<endl; 47 } 48 } 49 return 0; 50 }
Description
Diao Fei is very good at the game which names “Find the difference”. The game’s rule is giving two pictures and you should find all the differences between these two pictures.
Diao Ze is very good at math, and he thinks finding the differences in pictures is very boring, he giving a similar problem to Diao Fei: Giving you two number sequences, can you find the differences between these two number sequences?
To simplify the problem, the two number sequences satisfied:
·In each sequence, all the numbers are distinct.
·The first sequence has exactly one more number than the second sequence and there is only one number which is in the first sequence but not in the second sequence.
Your task is to help Diao Fei find the number which is in the first sequence but not in the second sequence.
Input
The first line contains an integer T, indicating the total number of test cases.
For each test case, there are three lines. The first line contains an integer n(), indicating the first sequence has n numbers and the second sequences has n-1 numbers. Then the second line contains n integers which in the first sequence and the third line contains n-1 integers which in the second sequence. Each integer in each sequence is less than 231.
Output
For each test case, output the answer in one line.
Sample Input
2 3 1 2 3 1 2 5 34 421 97 456 19238 421 19238 97 34
Sample Output
3 456
找缺失的数字,最好是位运算,这里就用求和就可以了
#include<stdio.h> //#include<bits/stdc++.h> #include<string.h> #include<iostream> #include<math.h> #include<sstream> #include<set> #include<queue> #include<map> #include<vector> #include<algorithm> #include<limits.h> #define inf 0x7fffffff #define INFL 0x7fffffffffffffff #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define LL long long #define ULL unsigned long long using namespace std; int main() { int t; while(cin>>t) { while(t--) { int n; int num; int sum=0; cin>>n; for(int i=0;i<n;i++) { cin>>num; sum+=num; } for(int i=0;i<n-1;i++) { cin>>num; sum-=num; } cout<<sum<<endl; } } return 0; }
Description
Every night Diao Ze is dreaming about the gold medal in the 1540th"> ACM-ICPC World Final. Not only does it represent the honor, but also Diao Ze likes the gold, and we know it is blingbling. Whenever Diao Ze gets a gold medal in his dream, he would weigh it again and again. Gosh, so tightfisted he is. For fear of losing any gold, he wants to know the certain weight of this gold medal. So he asks you for help in his dream.
Now you have a counter balance, like the picture above (you can put weight counters on both of the pans of the scale). Diao Ze wants to get the weight of the medal accurately, and he knows that the medal could not be heavier than N grams. If it is possible for Diao Ze to make the scale balanced with some certain different counter (any weight of the counter which has integer weight of grams is available for you, and the amount is infinite). Diao Ze could get the exact weight of the medal from the nominal weight of the counter. Pay attention, the counter with the same weight cannot be used more than once!
Input
The first line contains an integer T, indicating the total number of test cases. In each test case there is only one line contains an integer , indicating the maximum possible weight of the gold medal.
Output
For each test case, output the answer indicating the minimum number of counters, in that condition, you can make the scale balanced if the medal is x grams, no matter what x is, but satisfies .
Sample Input
3 3 4 5
Sample Output
2 2 3
这个解释在https://www.zhihu.com/question/30164499/answer/47003542
1 #include<stdio.h> 2 //#include<bits/stdc++.h> 3 #include<string.h> 4 #include<iostream> 5 #include<math.h> 6 #include<sstream> 7 #include<set> 8 #include<queue> 9 #include<map> 10 #include<vector> 11 #include<algorithm> 12 #include<limits.h> 13 #define inf 0x7fffffff 14 #define INFL 0x7fffffffffffffff 15 #define lson l,m,rt<<1 16 #define rson m+1,r,rt<<1|1 17 #define LL long long 18 #define ULL unsigned long long 19 using namespace std; 20 long long pow4(long a,long b) 21 { 22 long long r=1,base=a; 23 while(b!=0) 24 { 25 if(b&1) 26 r*=base; 27 base*=base; 28 b>>=1; 29 } 30 return r; 31 } 32 int main() 33 { 34 int t; 35 cin>>t; 36 while(t--) 37 { 38 int n; 39 int i=0; 40 cin>>n; 41 long long sum=0; 42 while(sum<n) 43 { 44 sum+=pow4(3,i); 45 i++; 46 } 47 cout<<i<<endl; 48 } 49 return 0; 50 }