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 ;
}

Atcoder ABC 069 C - 4-adjacent D - Grid Coloring的更多相关文章

  1. AtCoder ABC 042D いろはちゃんとマス目 / Iroha and a Grid

    题目链接:https://abc042.contest.atcoder.jp/tasks/arc058_b 题目大意: 给定一个 H * W 的矩阵,其中左下角 A * B 区域是禁区,要求在不踏入禁 ...

  2. AtCoder Regular Contest 080 D - Grid Coloring

    地址:http://arc080.contest.atcoder.jp/tasks/arc080_b 题目: D - Grid Coloring Time limit : 2sec / Memory ...

  3. ATCODER ABC 099

    ATCODER ABC 099 记录一下自己第一场AK的比赛吧...虽然还是被各种踩... 只能说ABC确实是比较容易. A 题目大意 给你一个数(1~1999),让你判断它是不是大于999. Sol ...

  4. Atcoder ABC 141

    Atcoder ABC 141 A - Weather Prediction SB题啊,不讲. #include<iostream> #include<cstdio> #inc ...

  5. Atcoder ABC 139E

    Atcoder ABC 139E 题意: n支球队大循环赛,每支队伍一天只能打一场,求最少几天能打完. 解法: 考虑抽象图论模型,既然一天只能打一场,那么就把每一支球队和它需要交手的球队连边. 求出拓 ...

  6. Atcoder ABC 139D

    Atcoder ABC 139D 解法: 等差数列求和公式,记得开 $ long long $ CODE: #include<iostream> #include<cstdio> ...

  7. Atcoder ABC 139C

    Atcoder ABC 139C 题意: 有 $ n $ 个正方形,选择一个起始位置,使得从这个位置向右的小于等于这个正方形的高度的数量最多. 解法: 简单递推. CODE: #include< ...

  8. Atcoder ABC 139B

    Atcoder ABC 139B 题意: 一开始有1个插口,你的插排有 $ a $ 个插口,你需要 $ b $ 个插口,问你最少需要多少个插排. 解法: 暴力模拟. CODE: #include< ...

  9. Atcoder ABC 139A

    Atcoder ABC 139A 题意: 给你两个字符串,记录对应位置字符相同的个数 $ (n=3) $ 解法: 暴力枚举. CODE: #include<iostream> #inclu ...

随机推荐

  1. 【codeforces 348B】Apple Tree

    [题目链接]:http://codeforces.com/problemset/problem/348/B [题意] 给你一棵树; 叶子节点有权值; 对于非叶子节点: 它的权值是以这个节点为根的子树上 ...

  2. PatentTips - Controlling voltage and frequency

    BACKGROUND OF THE INVENTION Mobile devices, such as but not limited to personal data appliances, cel ...

  3. 【推荐系统实战】:C++实现基于用户的协同过滤(UserCollaborativeFilter)

    好早的时候就打算写这篇文章,可是还是參加阿里大数据竞赛的第一季三月份的时候实验就完毕了.硬生生是拖到了十一假期.自己也是醉了... 找工作不是非常顺利,希望写点东西回想一下知识.然后再攒点人品吧,仅仅 ...

  4. UVALive 6084 Happy Camper(数学题)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  5. 汇编中中括号[]作用以及lea和mov指令的区别

    现在总结一下:其中牵扯到lea指令,mov指令,[] 一.lea指令:对于寄存器来说:第二个操作数是寄存器必须要加[],不然报错,这里lea就是取[寄存器]的值,如:mov eax,2lea ebx, ...

  6. 文件共享服务器nfs搭建过程

    网络文件共享服务器192. yum install -y nfs-utils 在exports文件中添加的从机范围 vim /etc/exports /home/nfs/ (rw,sync,fsid= ...

  7. POJ 2373 单调队列优化DP

    题意: 思路: f[i] = min(f[j]) + 1; 2 * a <= i - j <= 2 *b: i表示当前在第i个点.f[i]表示当前最少的线段个数 先是N^2的朴素DP(果断 ...

  8. atom玩法

    1.先用 git 下载一个 react-devtools: $ cd /some-directory$ git clone --recursive https://github.com/faceboo ...

  9. 【C#Windows 服务】 《三》Timer设置

    一.工具: VS2015+NET Framework4.5. 二.操作: 1.计时器设置: 2.日志代码: 三.代码: 1.日志代码: 1 /// <summary> 2 /// Wind ...

  10. 学习Go语言之简易ORM框架

    ORM即为对象关系映射,ORM常用于程序适配多种数据库,以达到开放扩展关闭修改的原则.笔者初学Golang,遂有意写个简易ORM框架,权当知识巩固. 首先需要有一个思想就是数据库表结构都是固定,但是每 ...