CQUPT WEEKLY TRAINING (7)DIV2 解题报告
来源:互联网 发布:软件系统运行报告 编辑:程序博客网 时间:2024/06/07 17:15
A题:题意背景就不描述了,阅读题。
总的说来就是,有4种优先级的东西,按照优先级挨着输出。如果优先级相同就输出较前面的。
rat>woman==child>man>captain。
数据比较小且优先级种类少,我挨着扫4遍就行了。
#include <cstdio>#include <algorithm>#include <cstring>#include <cmath>#include <iostream>#include <string>using namespace std;string a[105],b[105];int main(){ int n; while(scanf("%d",&n) != EOF) { for(int i=0;i<n;i++) { cin >> a[i] >> b[i]; } for(int i=0;i<n;i++) { if(b[i] == "rat") cout <<a[i] << endl; } for(int i=0;i<n;i++) { if(b[i] == "woman" || b[i] == "child") cout <<a[i]<< endl; } for(int i=0;i<n;i++) { if(b[i] == "man") cout <<a[i]<< endl; } for(int i=0;i<n;i++) { if(b[i] == "captain") cout << a[i] << endl; } } return 0;}
B题:n个有rankl的士兵进行训练。相同优先级视为一个group,每个group每轮只能有一个人训练升级。问需要多少代价把所有士兵的rank都提升为k。
统计每个优先级的士兵数,然后模拟训练过程,嗯哼!好像完了。
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <cmath>#include <string>using namespace std;int n,k;int a[111]= {0};int rank[111]= {0};int main(){ cin >> n >> k; for (int i=1; i<=n; i++) { cin >> a[i]; rank[a[i]]++; } int ans = 0; bool ok = true; while (ok) { ok=false; for (int i=k-1; i>=1; i--) { if (rank[i] > 0) { rank[i]--; rank[i+1]++; ok = true; } } if (ok) ans++; } cout << ans << endl; return 0;}
C题:
Bulls and Cows是一个猜数字游戏,一个人写下一个数字,另一个人猜这个数字,其中b代表位置正确的数字有几个,而c代表位置不正确的数字有几个。
其中猜的数字由 0 ~ 9 的不重复的4个数字组成。
给你n组数据,每行有三个数字,第一个是你猜的数字,第二个是b,第三个是c
现在如果可能猜出的结果有1个输出该数字,如果不止一个输出Need more data
如果结果不肯能出现输出Incorrect data。
直接暴力求解10000以内所有的结果,如果遇到求解的数字为符合所有的可能,记cnt++
如果cnt == 1 输出结果,cnt == 0 输出Incorrect data,如果cnt > 1输出Need more data。
#include <iostream>#include <cstdio>#include <cstring>using namespace std;struct Node{ int num[4]; int a,b;} node[20];int ans[4];int vis[11];bool ok(int num){ memset(vis,0,sizeof(vis)); int t; for(int i = 0; i < 4; i++) { t = num % 10; if(vis[t]) { return false; } ans[i] = t; vis[t] = 1; num /= 10; } return true;}int main(){ int n; char arr[5]; while(scanf("%d",&n) != EOF) { for(int i = 0; i < n; i++) { scanf("%s %d %d",arr,&node[i].a,&node[i].b); for(int j = 0; j < 4; j++) { node[i].num[j] = arr[j] - '0'; } } int cnt1,cnt2,cnt; cnt = 0; int res; for(int i = 1; i < 10000; i++) { if(ok(i)) { int j; for(j = 0; j < n; j++) { cnt1 = cnt2 = 0; for(int k = 0; k < 4; k++) { if(ans[k] == node[j].num[k]) { cnt1++; } if(vis[node[j].num[k]]) { cnt2++; } } if(cnt1 != node[j].a || cnt2 - cnt1 != node[j].b) { break; } } if(j == n) { res = i; cnt++; } } } if(cnt == 1) { for(int i = 0; i < 4; i++) { printf("%d",res%10); res /= 10; } printf("\n"); } else if(cnt > 1) { printf("Need more data\n"); } else { printf("Incorrect data\n"); } } return 0;}
D题:在一个字符串里面按着hello字符顺序找hello,找到就YES,否则NO;
贪心,挨着找过去就行了。
#include <cstdio>#include <algorithm>#include <cstring>#include <cmath>#include <iostream>#include <string>using namespace std;string s;string word = "hello";int main(){ while(cin >> s) { int flag = 0; for(int i=0;i<s.size();i++) { if(s[i] == word[flag]) flag++; if(flag == 5) break; } if(flag == 5) printf("YES\n"); else printf("NO\n"); } return 0;}
E题:生成保证一个数是前面出现所有数的约数的数组,保证数组最长。
只要枚举前一个数的所有约数,只要这个数能将前面一个数整除,必然能将前面的所有的数整除。
贪心思想:保证当前生出的约数最大,后面可找到更多的数。
#include <cstdio>#include <algorithm>#include <cstring>#include <cmath>#include <iostream>#include <string>using namespace std;int main(){ int n; cin >> n; cout << n; while(n>1) { int i; for(i=2; i<n; i++) if(n%i == 0) { n = n/i; cout << " " << n; break; } if(i == n) { cout << " " << 1; break; } } return 0;
F题:给一个序列代表一排树。现在需要把这排树砍成beautiful的。怎么叫beautiful的看题目。
呜~ 大概你需要明白2件事情。
1.beautiful sequence is can be determined with any member
2.at least one tree will remain the same height.
然后我们就统计一下,前一半中相对距离相同数量最多的那些树,后一半镜像统计,这个数量表示的就是我们最多可以不动的树的数量。
然后用n个去减掉这个最大数量,就是需要改变最小数量。
1.beautiful sequence is can be determined with any member
2.at least one tree will remain the same height.
然后我们就统计一下,前一半中相对距离相同数量最多的那些树,后一半镜像统计,这个数量表示的就是我们最多可以不动的树的数量。
然后用n个去减掉这个最大数量,就是需要改变最小数量。
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 100010;int a[maxn], d[maxn];int main(){ int n; while(scanf("%d", &n)!=EOF) { for(int i=1; i<=n; i++) scanf("%d",&a[i]); memset(d,0,sizeof(d)); int k = n/2 + n%2; for(int i=1; i<=k; i++) { if(a[i]-i+1>0) d[a[i]-i+1]++; } for(int i=n; i>k; i--) if(a[i]+i-n>0) d[a[i]+i-n]++; int ma = -1; for(int i=1; i<=100000; i++) ma = max(ma, d[i]); printf("%d\n", n - ma); } return 0;}
0 0
- CQUPT WEEKLY TRAINING (7)DIV2 解题报告
- CQUPT WEEKLY TRAINING (2)DIV2 解题报告
- CQUPT WEEKLY TRAINING (4)DIV2 解题报告
- CQUPT WEEKLY TRAINING (5)DIV2 解题报告
- CQUPT WEEKLY TRAINING (6)DIV2 解题报告
- CQUPT WEEKLY TRAINING (1)解题报告
- CQUPT WEEKLY TRAINING (3)解题报告
- Mango Weekly Training Round #3 解题报告
- Mango Weekly Training Round #6 解题报告
- 2015 CQUPT WEEKLY TRAINING (1)题解和专题内容推荐
- LeetCode Weekly Contest 56 解题报告
- codeforces #133 div2 解题报告
- codeforces #134 div2 解题报告
- SRM 556 DIV2 解题报告
- codeforce 192 div2解题报告
- 130720CF div2解题报告
- [Codeforces]Round246 div2 解题报告
- codeforces#254DIV2解题报告
- 关闭 MyEclipse 自动更新
- New balance 1dv0 mZL 0Oaus
- 内嵌汇编与C/C++实现的冒泡排序,快速排序算法排序500W个数据对比
- 清空StringBuffer和StringBuilder
- 附加功能-----发布交友信息
- CQUPT WEEKLY TRAINING (7)DIV2 解题报告
- 对分时线的分析,规划12.8日的压力
- Android FragmentActivity 内嵌Fragment,Listview notifyDataSetChanged() 不刷新
- HDU 1535 Invitation Cards 【SPFA + 链式前向星】
- HDU 5139 Formula
- 以下是《Learn Python The Hard Way, 2nd Edition》这本书的尾声部分。
- android 图片异步加载(线程池,等待,唤醒;图片缓存在内存)
- HTML 5:绘制旋转的太极图
- POJ1250解题报告