Atcoder ABC 069 C - 4-adjacent D - Grid Coloring
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
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≤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
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的更多相关文章
- AtCoder ABC 042D いろはちゃんとマス目 / Iroha and a Grid
题目链接:https://abc042.contest.atcoder.jp/tasks/arc058_b 题目大意: 给定一个 H * W 的矩阵,其中左下角 A * B 区域是禁区,要求在不踏入禁 ...
- AtCoder Regular Contest 080 D - Grid Coloring
地址:http://arc080.contest.atcoder.jp/tasks/arc080_b 题目: D - Grid Coloring Time limit : 2sec / Memory ...
- ATCODER ABC 099
ATCODER ABC 099 记录一下自己第一场AK的比赛吧...虽然还是被各种踩... 只能说ABC确实是比较容易. A 题目大意 给你一个数(1~1999),让你判断它是不是大于999. Sol ...
- Atcoder ABC 141
Atcoder ABC 141 A - Weather Prediction SB题啊,不讲. #include<iostream> #include<cstdio> #inc ...
- Atcoder ABC 139E
Atcoder ABC 139E 题意: n支球队大循环赛,每支队伍一天只能打一场,求最少几天能打完. 解法: 考虑抽象图论模型,既然一天只能打一场,那么就把每一支球队和它需要交手的球队连边. 求出拓 ...
- Atcoder ABC 139D
Atcoder ABC 139D 解法: 等差数列求和公式,记得开 $ long long $ CODE: #include<iostream> #include<cstdio> ...
- Atcoder ABC 139C
Atcoder ABC 139C 题意: 有 $ n $ 个正方形,选择一个起始位置,使得从这个位置向右的小于等于这个正方形的高度的数量最多. 解法: 简单递推. CODE: #include< ...
- Atcoder ABC 139B
Atcoder ABC 139B 题意: 一开始有1个插口,你的插排有 $ a $ 个插口,你需要 $ b $ 个插口,问你最少需要多少个插排. 解法: 暴力模拟. CODE: #include< ...
- Atcoder ABC 139A
Atcoder ABC 139A 题意: 给你两个字符串,记录对应位置字符相同的个数 $ (n=3) $ 解法: 暴力枚举. CODE: #include<iostream> #inclu ...
随机推荐
- #undef 的用法
在Visual Studio2008中编写如下代码: #include <iostream> using namespace std; int main() { #define MODI ...
- "duplicate symbol for architecture i386" 解决的方法
我在写项目的过程中,碰到了这个错误,我在网上查了一下,发现这个错误的原因是,project里面有反复的类. 解决方式:找到反复的类,然后删除掉就好了. 分析一下, 如图. 能够看出, 错误类型是 du ...
- hdu4089Activation 概率dp
//一条队列对于第一个人的情况 //概率p1:队列保持不变 //p2:第一个人到队尾 //p3:第一个人出队 //p4:系统崩溃 //队列中有N个人,Tomato 在第M位置,求系统崩溃.Tomato ...
- MyEclipse常见错误汇总,中英注释版(长期更新)
No.1 当一条语句漏写分号时错误描述如下 Syntax error, insert ";" to complete Statement(语法错误:插入分号完成语句描述) No.2 ...
- nodejs是什么
nodejs是什么 一种javascript的运行环境,能够使得javascript脱离浏览器运行. 阅读本帖需要先复习小学语文课文,华罗庚的<统筹方法>. 比如,想泡壶茶喝.当时的情况是 ...
- [JSOI2008] [BZOJ1567] Blue Mary的战役地图 解题报告 (hash)
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1567 Description Blue Mary最近迷上了玩Starcraft(星际争霸 ...
- Laravel-路由组和中间件
Laravel-路由组和中间件 标签(空格分隔): php 定义路由组 Route::group(['prefix'=>'Anime'], function(){ Rout::match(['g ...
- 实时监控Cat之旅~对请求是否正常结束做监控(分布式的消息树)
对基于请求的分布式消息树的分析 在MVC时有过滤器System.Web.Mvc.ActionFilterAttribute,它可以对action执行的整个过程进行拦截,执行前与执行后我们可以注入自己的 ...
- Android属性动画-ValueAnimator和ObjectAnimator的高级用法
ValueAnimator的高级用法 在上篇文章中介绍补间动画缺点的时候有提到过,补间动画是只能对View对象进行动画操作的.而属性动画就不再受这个限制,它可以对任意对象进行动画操作.那么大家应该还记 ...
- vue打包后js和css、图片不显示,引用的字体找不到问题
vue打包后js和css.图片不显示,引用的字体找不到问题:图片一般都是背景图片. 一.vue打包出现js和css不显示问题: 1.不使用mode:'history' 2.使用mode:'histor ...