AtCoder Regular Contest 080 C , D
来源:互联网 发布:平果笔记本屏幕软件 编辑:程序博客网 时间:2024/06/06 12:52
C - 4-adjacent
Time limit : 2sec / Memory limit : 256MB
Score : 400 points
Problem Statement
We have a sequence of length N, a=(a1,a2,…,aN). Each ai is a positive integer.
Snuke’s objective is to permute the element in a so that the following condition is satisfied:
For each 1≤i≤N−1, the product of ai and ai+1 is a multiple of 4.
Determine whether Snuke can achieve his objective.
Constraints
2≤N≤105
ai is an integer.
1≤ai≤109
Input
Input is given from Standard Input in the following format:
N
a1 a2 … aN
Output
If Snuke can achieve his objective, print Yes; otherwise, print No.
Sample Input 1
Copy
3
1 10 100
Sample Output 1
Copy
Yes
One solution is (1,100,10).
Sample Input 2
Copy
4
1 2 3 4
Sample Output 2
Copy
No
It is impossible to permute a so that the condition is satisfied.
Sample Input 3
Copy
3
1 4 1
Sample Output 3
Copy
Yes
The condition is already satisfied initially.
Sample Input 4
Copy
2
1 1
Sample Output 4
Copy
No
Sample Input 5
Copy
6
2 7 1 8 2 8
Sample Output 5
Copy
Yes
#include <bits/stdc++.h>using namespace std;int a[123456];int main(){ int n; scanf("%d",&n); int h=0,s=0,k=0; for(int i=0;i<n;i++){ scanf("%d",&a[i]); if(a[i]%4==0) h++; else if(a[i]%2==0) s++; else k++; } if(h>=k){ puts("Yes"); } else { if(s==0){ if(h+1>=k){ puts("Yes"); } else { puts("No"); } } else { n-=(2*h); n-=s; if(n>0){ puts("No"); } else { puts("Yes"); } } } return 0;}
D - Grid Coloring
Time limit : 2sec / Memory limit : 256MB
Score : 400 points
Problem Statement
We have a grid with H rows and W columns of squares. Snuke is painting these squares in colors 1, 2, …, N. Here, the following conditions should be satisfied:
For each i (1≤i≤N), there are exactly ai squares painted in Color i. Here, a1+a2+…+aN=HW.
For each i (1≤i≤N), the squares painted in Color i are 4-connected. That is, every square painted in Color i can be reached from every square painted in Color i by repeatedly traveling to a horizontally or vertically adjacent square painted in Color i.
Find a way to paint the squares so that the conditions are satisfied. It can be shown that a solution always exists.
Constraints
1≤H,W≤100
1≤N≤HW
ai≥1
a1+a2+…+aN=HW
Input
Input is given from Standard Input in the following format:
H W
N
a1 a2 … aN
Output
Print one way to paint the squares that satisfies the conditions. Output in the following format:
c11 … c1W
:
cH1 … cHW
Here, cij is the color of the square at the i-th row from the top and j-th column from the left.
Sample Input 1
Copy
2 2
3
2 1 1
Sample Output 1
Copy
1 1
2 3
Below is an example of an invalid solution:
1 2
3 1
This is because the squares painted in Color 1 are not 4-connected.
Sample Input 2
Copy
3 5
5
1 2 3 4 5
Sample Output 2
Copy
1 4 4 4 3
2 5 4 5 3
2 5 5 5 3
Sample Input 3
Copy
1 1
1
1
Sample Output 3
Copy
1
Submit
#include <bits/stdc++.h>using namespace std;struct node{ int id; int val; bool operator < (const node& a) const{ return val<a.val; }}a[100*100+100];int str[105][105];int main(){ int n,m; cin>>n>>m; int k; cin>>k; int h=0; for(int i=1;i<=k;i++){ int g; scanf("%d",&g); a[h].id=i; a[h].val=g; h++; } sort(a,a+h); h=0; for(int i=1;i<=n;i++){ if(i%2){ for(int j=1;j<=m;j++){ str[i][j]=a[h].id; a[h].val--; if(a[h].val==0){ h++; } } } else { for(int j=m;j>=1;j--){ str[i][j]=a[h].id; a[h].val--; if(a[h].val==0){ h++; } } } } for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ printf("%d ",str[i][j]); } puts(""); } return 0;}
- AtCoder Regular Contest 080 C , D
- AtCoder Regular Contest 080-D
- AtCoder Regular Contest 080-C
- AtCoder Regular Contest 079 C D E
- AtCoder Regular Contest 069 D
- AtCoder Regular Contest 073 D
- AtCoder Regular Contest 077-D
- AtCoder Regular Contest 078 D
- AtCoder Regular Contest 078 D
- AtCoder Regular Contest 078-D
- AtCoder Regular Contest 079-D
- AtCoder Regular Contest 079 D
- AtCoder Regular Contest 081 D
- AtCoder Regular Contest 068-D
- atcoder AtCoder Regular Contest 084 D
- AtCoder Regular Contest 077-C
- AtCoder Regular Contest 078-C
- AtCoder Regular Contest 079-C
- MySQL性能分析及explain的使用
- 简单实现短信验证码的倒计时效果
- Ignatius and the Princess IV --DP
- 艺术家薛林兴、陈葆棣一行来访汪国新北京诗书画院
- 代码走读之client处理流程(不断更新)
- AtCoder Regular Contest 080 C , D
- maven工程创建详解:java、javaweb
- netstat 命令--help
- 判断是否是md5
- ubuntu系统使用opencv,make通过,但运行时报错
- SOCKET通信
- html开放式标签(单标签)斜杠书写问题
- 差比数列通解(1.6)
- ARKit从入门到精通(8)-ARKit捕捉平地