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≤iN−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

3
1 10 100

Sample Output 1

Yes

One solution is (1,100,10).


Sample Input 2

4
1 2 3 4

Sample Output 2

No

It is impossible to permute a so that the condition is satisfied.


Sample Input 3

3
1 4 1

Sample Output 3

Yes

The condition is already satisfied initially.


Sample Input 4

2
1 1

Sample Output 4

No

Sample Input 5

6
2 7 1 8 2 8

Sample Output 5

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=;
for(int i=;i<n;i++)
{
scanf("%d",&x);
if(!(x%)) a++;
else if(x&) b++;
else c++;
}
if(!c) b--;
puts(a>=b?"Yes":"No");
}
return ;
}

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≤iN), there are exactly ai squares painted in Color i. Here, a1+a2+…+aN=HW.
  • For each i (1≤iN), 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≤NHW
  • 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

2 2
3
2 1 1

Sample Output 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.


Sample Input 2

3 5
5
1 2 3 4 5

Sample Output 2

1 4 4 4 3
2 5 4 5 3
2 5 5 5 3

Sample Input 3

1 1
1
1

Sample Output 3

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[][];
int h,w,n,x,k;
int main()
{
while(scanf("%d%d%d",&h,&w,&n)!=EOF)
{
mem(g);
k=-;
for(int i=;i<=n;i++)
{
scanf("%d",&x);
while(x--) k++,g[(k/h)&?(h--(k%h)):k%h][k/h]=i;
}
for(int i=;i<h;i++)
{
for(int j=;j<w;j++)
{
if(j) printf(" ");
printf("%d",g[i][j]);
}
printf("\n");
}
}
return ;
}

最新文章

  1. 事后分析报告(Postmortem Report)
  2. Codeforces 732D [二分 ][贪心]
  3. C/C++实践笔记_002编译和链接
  4. split() 注意事项.
  5. URL 学习总结
  6. mysql时间处理
  7. NOIP2014酱油记
  8. eclipse使用外部maven时multiModuleProjectDirectory错误解决
  9. 【原创】大数据基础之Spark(4)RDD原理及代码解析
  10. ELK 起航
  11. 用 pyinstaller 打包含xpinyin 库的Python程序
  12. SqlDataAdapter更新数据
  13. 2. mysql 语句
  14. 测试环境的好工具bginfo
  15. (1)什么是socket(套接字)
  16. maven使用内嵌tomcat7
  17. OK6410 rmmod卸载模块失败:No such file or directory -- 转
  18. 调整linux系统时区
  19. &quot;废物利用&quot;也抄袭——“完全”DIY&quot;绘图仪&quot;&lt;一、准备工作&gt;
  20. Codeforces 543.B Destroying Roads

热门文章

  1. [terry笔记]oracle里的执行计划-查看
  2. phpstorm 激活方法
  3. 支持并发的httpclient(基于tcp连接池以及netty)
  4. 如何将网站升级为HTTPS协议(整理)
  5. 解读邮箱正则表达式:^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$
  6. [NOIP2015模拟10.22] 最大子矩阵 解题报告(单调栈)
  7. [NOIP2015模拟10.22] 最小代价 解题报告 (最小生成树)
  8. 【DNN 系列】 模块开发 8.0.1
  9. Windows 相关
  10. [ xml ] [ log4j2 ] No grammar constraints (DTD or XML Schema) referenced in the document.