Codeforces Round #419 (Div. 2)
来源:互联网 发布:hr软件 免费 编辑:程序博客网 时间:2024/05/21 09:14
codeforces Round#419普通的一场div2.
codeforces816A
题意:输入四个数,模拟时钟的走向,分针到60进位变成00,时针到24变成00,问最少经过多少步,使得其变成回文。
两种方法:第一种经过if,else判断,有几个坑,例如06:43等等,第二种方法直接while循环判断两个数字其中一个倒过来是否相同。我是用第一种判坑写的。
#include <bits/stdc++.h>#define INF 0x3f3f3f3f#define eps 1e-8#define MAXN (100000+10)#define MAXM (50000000)#define Si(a) scanf("%d", &a)#define Sl(a) scanf("%lld", &a)#define Sf(a) scanf("%lf", &a)#define Ss(a) scanf("%s", a)#define Sc(a) scanf(" %c", &a)#define Pi(a) printf("%d\n", (a))#define Pf(a) printf("%lf\n", (a))#define Pl(a) printf("%lld\n", (a))#define Ps(a) printf("%s\n", (a))#define MOD 1000000007#define LL long long#define lson l, mid, o<<1#define rson mid+1, r, o<<1|1#define lowbits(x) (x & -x)using namespace std;int main(void){ int M, N, M1, N1; char s[10]; scanf("%s", s); M=s[0]-'0'; N=s[1]-'0'; M1=s[3]-'0'; N1=s[4]-'0'; int cnt=0; if(N1==M&&M1==N) { printf("0\n"); return 0; } int m=N*10+M; int n=M1*10+N1; int k=M*10+N; if(m>=n) { if(N<=5) cnt=m-n; else { if(M==0) cnt=60*(10-N)-(n-1); else cnt=60*(10-N)-(n-2); } } else { if(M*10+N<23) { if(N<5) cnt=60-n+(k+1)/10+((k+1)%10)*10; else { if(M==0) { cnt=60*(10-N)-(n-1); } else cnt=60*(10-N)-(n-2); } } else cnt=60-n; } printf("%d\n", cnt); return 0;}
第二题题意:给你n个区间,然后有k个询问区间,问这k个区间中每个区间在n个区间重叠部分大于m的数有几个…(有点智障说不清楚)以为是线段树,其实用个辅助数组a[i]表示第i个元素以后全部加a[i]..
代码如下:
#include <bits/stdc++.h>#define INF 0x3f3f3f3f#define eps 1e-8#define MAXN (100000+10)#define MAXM (50000000)#define Si(a) scanf("%d", &a)#define Sl(a) scanf("%lld", &a)#define Sf(a) scanf("%lf", &a)#define Ss(a) scanf("%s", a)#define Sc(a) scanf(" %c", &a)#define Pi(a) printf("%d\n", (a))#define Pf(a) printf("%lf\n", (a))#define Pl(a) printf("%lld\n", (a))#define Ps(a) printf("%s\n", (a))#define MOD 1000000007#define LL long long#define lson l, mid, o<<1#define rson mid+1, r, o<<1|1#define lowbits(x) (x & -x)using namespace std;int n, k, q, a[200100], b[200100];int main(void){ while(scanf("%d%d%d", &n, &k, &q)!=EOF) { int x, y; memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); for(int i=1; i<=n; i++) { scanf("%d%d", &x,&y); a[x]++; a[y+1]--; } for(int i=1; i<=200100; i++) { a[i]+=a[i-1]; b[i]=b[i-1]+(a[i]>=k); } for(int i=1; i<=q; i++) { scanf("%d%d", &x, &y); printf("%d\n", b[y]-b[x-1]); } } return 0;}
第三题题意:初始为0的二维数组,每项步骤为行或者列加一,求最少步骤。很简单的模拟题,只需要判断行和列的大小再进行相应模拟。
代码如下:
#include <bits/stdc++.h>#define INF 0x3f3f3f3f#define eps 1e-8#define MAXN (100000+10)#define MAXM (50000000)#define Si(a) scanf("%d", &a)#define Sl(a) scanf("%lld", &a)#define Sf(a) scanf("%lf", &a)#define Ss(a) scanf("%s", a)#define Sc(a) scanf(" %c", &a)#define Pi(a) printf("%d\n", (a))#define Pf(a) printf("%lf\n", (a))#define Pl(a) printf("%lld\n", (a))#define Ps(a) printf("%s\n", (a))#define MOD 1000000007#define LL long long#define lson l, mid, o<<1#define rson mid+1, r, o<<1|1#define lowbits(x) (x & -x)using namespace std;int M, N, a[200][200];struct node{ string s; int x, y;};vector<node> v;int cnt;void up1(){ for(int i=1; i<=M; i++) { int Min=INF; for(int j=1; j<=N; j++) Min=min(Min, a[i][j]); cnt+=Min; if(Min==0)continue; node n; for(int j=1; j<=N; j++) a[i][j]-=Min; n.s="row", n.x=i, n.y=Min; v.push_back(n); }}void up2(){ for(int i=1; i<=N; i++) { int Min=INF; for(int j=1; j<=M; j++) Min=min(Min, a[j][i]); cnt+=Min; if(Min==0)continue; node n; for(int j=1; j<=M; j++) a[j][i]-=Min; n.s="col", n.x=i, n.y=Min; v.push_back(n); }}int main(void){ while(scanf("%d%d", &M, &N)!=EOF) { cnt=0; memset(a, 0, sizeof(a)); for(int i=1; i<=M; i++) for(int j=1; j<=N; j++) scanf("%d", &a[i][j]); if(M<=N)up1(),up2(); else up2(), up1(); bool flag=true; for(int i=1; i<=M; i++) for(int j=1; j<=N; j++) if(a[i][j])flag=false; if(flag) { printf("%d\n", cnt); for(int i=1; i<=v.size(); i++) { for(int j=1; j<=v[i-1].y; j++) cout<<v[i-1].s<<" "<<v[i-1].x<<endl; } } else cout<<"-1"<<endl; } return 0;}
阅读全文
0 0
- Codeforces Round #419 (Div. 2)
- Codeforces Round #419 (Div. 2)
- Codeforces Round #419 (Div. 2)
- Codeforces Round #419 (Div. 2)
- Codeforces Round #419 (Div. 2)
- Codeforces Round #419 (Div. 2)(A+B)
- Codeforces Round #419 (Div. 2) D
- Codeforces Round #419 (Div. 2) 题解
- Codeforces Round #419 (Div. 2) A
- Codeforces Round#419 (div.1)
- Codeforces Round #102 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #104 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #107 (Div. 2)
- Codeforces Round #108 (Div. 2)
- 解决UGUI Scroll View关闭Horizontal时遇到的问题
- 后缀表达式的java实现
- 对 工厂模式与建造者模式 的个人理解,以及结合运用
- hdu 5535 Cake 构造+记忆化搜索
- python在linux中输出带颜色的文字的方法
- Codeforces Round #419 (Div. 2)
- Swift版本报错
- java反射类的相关知识
- 网站发布阶段的跌跌撞撞
- 拉姆达表达式相关知识
- mybatis与hibernate本质的区别以及应用的场景
- 安卓常用的设计模式之观察者模式
- 安卓设计模式之原型模式
- 正则表达式各种字符含义(链接)