codeforces493 A. Vasya and Football B. Vasya and Wrestling C. Vasya and Basketball
来源:互联网 发布:asio mac驱动 编辑:程序博客网 时间:2024/05/20 11:20
A. Vasya and Football
这个题目很简单,只需要按照提议模拟一下即可,注意模拟的时候要先按照时间排序,一旦某个人已经被提示红牌,就不在对其考虑;
#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#define MAX 110#define ll __int64using namespace std;char sname[30], tname[30];int a[MAX],b[MAX];struct Node{int time; //被警告的时间 char c1[10]; //所属的队名 int num;char c2[10]; //是什么类型的警告 bool operator < (const Node& rhs ) const{return rhs.time > time;}}p[MAX]; //记录每个队员的属性 int main(){int n;while (scanf("%s%s",sname,tname) != EOF){scanf("%d",&n);for (int i = 0; i<n; i++){scanf("%d%s%d%s",&p[i].time,p[i].c1,&p[i].num,p[i].c2);}sort(p,p+n);memset(a,0,sizeof(a)); //记录'h'队的队员是否已经被提示红牌 memset(b,0,sizeof(b)); //记录'a'队的队员是否已经被提示红牌 //for (int i = 0; i<n; i++) printf("%d ",p[i].time); printf("\n");for (int i = 0; i<n; i++){char u = p[i].c1[0], v = p[i].c2[0];int x = p[i].time, y = p[i].num;if (u == 'h'){if (a[y] >= 2){ //该队员若已经被提示红牌,则忽略 continue;}if (v == 'r'){printf("%s %d %d\n",sname,y,x);a[y] = 2;}if (v == 'y'){a[y]++;if (a[y] >= 2){printf("%s %d %d\n",sname,y,x);}}}else{if (b[y] >= 2){continue;}if (v == 'r'){printf("%s %d %d\n",tname,y,x);b[y] = 2;}if (v == 'y'){b[y]++;if (b[y] >= 2){printf("%s %d %d\n",tname,y,x);}}}}}}
B. Vasya and Wrestling
很水的模拟题,只需要按照题目的条件逐一判断即可,一旦在某个条件下能够分出胜负,就不在判断,注意可能会爆int:
判断的顺序为:
1、和是否相同;
2、字典序是否相同;
3、最后一次后奖励的是谁;
#include<cstdio>#include<cstring>#include<algorithm>#define MAX 100010#define ll __int64using namespace std;ll a[MAX],b[MAX];int main(){int n;int u,v;while (scanf("%d",&n) != EOF){u = 0;v = 0;ll t;ll sum1 = 0, sum2 = 0;for (int i = 0; i<n; i++){scanf("%I64d",&t);if (t > 0){a[u++] = t;sum1 += t;}else{b[v++] = -t;sum2 += (-t);}}if (sum1 > sum2){printf("first\n");continue;}if (sum1 < sum2){printf("second\n");continue;}//for (int i = 0; i<u; i++) printf("%d ",a[i]); printf("\n");//for (int i = 0; i<v; i++) printd("%d ",b[i]); printf("\n");int sign = -1;for (int i = 0; i<min(u,v); i++){if (a[i] > b[i]){sign = 0;break;}if (a[i] < b[i]){sign = 1;break;}}if (sign == 0){ printf("first\n"); continue;}if (sign == 1){printf("second\n");continue;}if (u > v){ printf("first\n"); continue;}if (u < v){printf("second\n");continue;}if (t > 0){printf("first\n");}else{printf("second\n");}}return 0;}
C. Vasya and Basketball
这个题目当时做的时候想了一会,觉得是用二分,并且c++里面有很好的函数库可以用,就开始写了,结果脑残了一下,最后有个条件(a应该取最大值)没有判断,WA了两次,耽误了好久的时间。思路很简单,就是枚举d值,然后二分去找大于d的第一个数的位置,然后直接根据题目要求,找出结果就好,注意,d取0和取无穷大的情况;
#include<cstdio>#include<cstring>#include<algorithm>#define MAX 200010#define ll __int64#define INF 10000000000using namespace std;ll a[MAX],b[MAX];ll c[MAX*2]; //存放所有可能的d值,容易看出d只需取a,b中出现的值和0,INF即可代表所有情况 int main(){ int n,m; while (scanf("%d",&n) != EOF){ int cnt = 0; c[cnt++] = 0; for (int i = 1; i<=n; i++){ scanf("%I64d",&a[i]); c[cnt++] = a[i]; } scanf("%d",&m); for (int i = 1; i<=m; i++){ scanf("%I64d",&b[i]); c[cnt++] = b[i]; } c[cnt++] = INF; sort(a+1,a+n+1); sort(b+1,b+m+1); sort(c,c+cnt); cnt = unique(c,c+cnt) - c; ll ans = -INF, u, v, t1, t2; for (int i = 0; i<cnt; i++){ int x = upper_bound(a+1,a+n+1,c[i]) - a; //找到在a中第一个严格大于c[i]的元素的位置 int y = upper_bound(b+1,b+m+1,c[i]) - b; t1 = (x-1)*2 + (n-x+1)*3; t2 = (y-1)*2 + (m-y+1)*3; if (t1 - t2 > ans){ ans = t1 - t2; u = t1; v = t2; } else if (t1 - t2 == ans && t1 > u){ //注意u应该取最大值,因为少加了t1 > u的判断WA了两次 .o(╯□╰)o u = t1; v = t2; } } printf("%I64d:%I64d\n",u,v); } return 0;}
0 0
- codeforces493 A. Vasya and Football B. Vasya and Wrestling C. Vasya and Basketball
- B. Vasya and Wrestling
- B. Vasya and Wrestling
- C. Vasya and Basketball
- A. Vasya and Football
- A Vasya and Football
- A. Vasya and Football
- CF493B Vasya and Wrestling
- codeforces Vasya and Basketball
- Vasya and Basketball
- 493A Vasya and Football
- CodeForces 493B Vasya and Wrestling 【模拟】
- Codeforces 493B Vasya and Wrestling(水)
- codeforces 493C Vasya and Basketball
- CF_493 C- Vasya and Basketball(二分)
- CodeForces 493C Vasya and Basketball
- codeforces 493C Vasya and Basketball(枚举)
- Codeforces 493C Vasya and Basketball(暴力)
- Timer和ScheduledExecutorService
- java IO相关API探索之Buffer类
- 始动:hello world-cpp
- HMM简介
- 大端模式和小端模式的概念以及使用程序来辨别
- codeforces493 A. Vasya and Football B. Vasya and Wrestling C. Vasya and Basketball
- hihoCoder:1039字符串消除
- 1096 A+B for Input-Output Practice (VIII)
- android源码在windows平台下的下载的几种方式
- 做PPT需要注意的问题
- 十一月总结
- 莫比乌斯反演 -- ACdreamer
- 邻接矩阵的练习
- javascript 文本下拉提示