标签:square initial 1.0 string time format out follow mem
Time limit : 2sec / Memory limit : 256MB
Score : 400 points
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:
Determine whether Snuke can achieve his objective.
Input is given from Standard Input in the following format:
N a1 a2 … aN
If Snuke can achieve his objective, print Yes
; otherwise, print No
.
3 1 10 100
Yes
One solution is (1,100,10).
4 1 2 3 4
No
It is impossible to permute a so that the condition is satisfied.
3 1 4 1
Yes
The condition is already satisfied initially.
2 1 1
No
6 2 7 1 8 2 8
Yes
1~n-1之间保证a[i]*a[i+1]%4==0
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <vector> #include <queue> #include <stack> #include <cstdlib> #include <iomanip> #include <cmath> #include <cassert> #include <ctime> #include <map> #include <set> using namespace std; #define lowbit(x) (x&(-x)) #define max(x,y) (x>y?x:y) #define min(x,y) (x<=y?x:y) #define MAX 100000000000000000 #define MOD 1000000007 #define pi acos(-1.0) #define ei exp(1) #define PI 3.141592653589793238462 #define ios() ios::sync_with_stdio(false) #define INF 1044266558 #define mem(a) (memset(a,0,sizeof(a))) typedef long long ll; int a,b,c,x,n; int main() { while(scanf("%d",&n)!=EOF) { a=b=c=0; for(int i=0;i<n;i++) { scanf("%d",&x); if(!(x%4)) a++; else if(x&1) b++; else c++; } if(!c) b--; puts(a>=b?"Yes":"No"); } return 0; }
Time limit : 2sec / Memory limit : 256MB
Score : 400 points
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:
Find a way to paint the squares so that the conditions are satisfied. It can be shown that a solution always exists.
Input is given from Standard Input in the following format:
H W N a1 a2 … aN
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.
2 2 3 2 1 1
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.
3 5 5 1 2 3 4 5
1 4 4 4 3 2 5 4 5 3 2 5 5 5 3
1 1 1 1
1
h*w的网格,填充颜色,颜色种类为n,a[i]*****a[n],为每种颜色的个数,保证所填充相等颜色之间必须联通,蛇形填充就行。
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <vector> #include <queue> #include <stack> #include <cstdlib> #include <iomanip> #include <cmath> #include <cassert> #include <ctime> #include <map> #include <set> using namespace std; #define lowbit(x) (x&(-x)) #define max(x,y) (x>y?x:y) #define min(x,y) (x<=y?x:y) #define MAX 100000000000000000 #define MOD 1000000007 #define pi acos(-1.0) #define ei exp(1) #define PI 3.141592653589793238462 #define ios() ios::sync_with_stdio(false) #define INF 1044266558 #define mem(a) (memset(a,0,sizeof(a))) typedef long long ll; int g[110][110]; int h,w,n,x,k; int main() { while(scanf("%d%d%d",&h,&w,&n)!=EOF) { mem(g); k=-1; for(int i=1;i<=n;i++) { scanf("%d",&x); while(x--) k++,g[(k/h)&1?(h-1-(k%h)):k%h][k/h]=i; } for(int i=0;i<h;i++) { for(int j=0;j<w;j++) { if(j) printf(" "); printf("%d",g[i][j]); } printf("\n"); } } return 0; }
Atcoder ABC 069 C - 4-adjacent D - Grid Coloring
标签:square initial 1.0 string time format out follow mem
原文地址:http://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/7473161.html