华中农业大学预赛
2016-05-15 17:36
399 查看
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![](http://211.69.133.223/image/problem-img/3.png)
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![](http://acm.hzau.edu.cn/upload/201605/6(2).png)
and
![](http://acm.hzau.edu.cn/upload/201605/7(1).png)
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
#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--) { double a,b; cin>>a>>b; printf("%.2f\n",b/a); } } return 0; }
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![](http://acm.hzau.edu.cn/upload/201605/7(2).png)
![](http://acm.hzau.edu.cn/upload/201605/8.png)
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
#include <iostream> #include <stdio.h> #include <string.h> using namespace std; int main() { long long t; scanf("%lld",&t); while(t--) { long long ans=0; long long a,b; long long i; scanf("%lld%lld",&a,&b); long long MIN=min(a,b); ans+=max(a-b,0LL)*b; for(i=2; i<=MIN; i++) { if(b%i!=0) { long long d=b/i; long long L=min((b%i)/d+1,MIN-i+1); ans+=(b%i)*L+((L-1)*L/2)*(-1*d); i+=L-1; // cout<<ans<<endl; // d=0; } } printf("%lld\n",ans); } return 0; }
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:![](http://acm.hzau.edu.cn/upload/201605/1(3).png)
![](http://acm.hzau.edu.cn/upload/201605/2(15).png)
![](http://acm.hzau.edu.cn/upload/201605/4(9).png)
![](http://acm.hzau.edu.cn/upload/201605/5(5).png)
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(![](http://acm.hzau.edu.cn/upload/201605/10.png)
![](http://acm.hzau.edu.cn/upload/201605/11.png)
) 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(
![](http://acm.hzau.edu.cn/upload/201605/15.png)
,
![](http://acm.hzau.edu.cn/upload/201605/16.png)
) 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. .....
#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; char mp[100][100]; int main() { int t; cin>>t; while(t--) { int n,m,num; int x,y; cin>>n>>m>>num; for(int i=0;i<=n+1;i++) { for(int j=0;j<=m+1;j++) { mp[i][j]='.'; } } for(int i=1; i<=num; i++) { cin>>x>>y; mp[x][y]='M'; if(mp[x-1][y]=='x') { mp[x-1][y]='N'; } if(mp[x][y-1]=='x') { mp[x][y-1]='N'; } if(mp[x+1][y]=='x') { mp[x+1][y]='N'; } if(mp[x][y+1]=='x') { mp[x][y+1]='N'; } if(mp[x-1][y-1]=='x') { mp[x-1][y-1]='N'; } if(mp[x-1][y+1]=='x') { mp[x-1][y+1]='N'; } if(mp[x+1][y-1]=='x') { mp[x+1][y-1]='N'; } if(mp[x+1][y+1]=='x') { mp[x+1][y+1]='N'; } } for(int i=1; i<=n; i++) { for(int j=1; j<=m; j++) { if(mp[i][j]=='.') { int ans=0; for(int s=i-1;s<=i+1;s++) { for(int c=j-1;c<=j+1;c++) { if(mp[s][c]=='M') { ans++; } } } if(ans) { mp[i][j]=ans+'0'; } } // cout<<mp[i][j]; } // cout<<endl; } for(int i=1; i<=n; i++) { for(int j=1; j<=m; j++) { cout<<mp[i][j]; } cout<<endl; } cout<<endl; } return 0; }
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(![](http://acm.hzau.edu.cn/upload/201605/1(6).png)
), 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 数据量小,我们暴力就好~
#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 b=10000; int a[1000]; cin>>n; for(int i=0;i<n;i++) { cin>>a[i]; } for(int i=0;i<n;i++) { for(int j=i+1;j<n;j++) { if(a[i]==a[j]) { b=min(b,j-i); } } } cout<<b<<endl; } } return 0; }
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(![](http://acm.hzau.edu.cn/upload/201605/1(7).png)
), 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.![](http://acm.hzau.edu.cn/upload/201605/1(5).png)
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![](http://acm.hzau.edu.cn/upload/201605/2(11).png)
, 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![](http://acm.hzau.edu.cn/upload/201605/3(4).png)
.
Sample Input
3 3 4 5
Sample Output
2 2 3
这个解释在https://www.zhihu.com/question/30164499/answer/47003542
#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; long long pow4(long a,long b) { long long r=1,base=a; while(b!=0) { if(b&1) r*=base; base*=base; b>>=1; } return r; } int main() { int t; cin>>t; while(t--) { int n; int i=0; cin>>n; long long sum=0; while(sum<n) { sum+=pow4(3,i); i++; } cout<<i<<endl; } return 0; }
相关文章推荐
- 学习进度第十一周
- Intellij Idea系列之Tomcat环境的搭建(三)
- fastjson使用示例
- MyBatis的动态SQL详解
- 被动信息收集:信息收集内容、信息用途、信息收集DNS、DNS信息收集-NSLOOKUP
- cookie读写JS
- (三)maven出错记录
- <css3>border
- MFC判断Listctrl当前选中的单元格的行和列
- Hive体系结构(三)元数据库与基本操作
- 《OS之缓冲技术》
- JavaSE_遍历Properties
- hdu 5680 zxa and set
- LCA 离线算法: tarjan
- Excel Sheet Column Number
- JSF可以直接以方法作为属性值
- 组个最小数
- nyoj954n!(变形)
- 打印空心字符菱形
- Java 泛型,了解这些就够用了。