当前位置:网站首页>A. Color the Picture- Codeforces Round #810 (Div. 1)
A. Color the Picture- Codeforces Round #810 (Div. 1)
2022-08-03 21:03:00 【秦小咩】
A. Color the Picture
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
A picture can be represented as an n×mn×m grid (nn rows and mm columns) so that each of the n⋅mn⋅m cells is colored with one color. You have kk pigments of different colors. You have a limited amount of each pigment, more precisely you can color at most aiai cells with the ii-th pigment.
A picture is considered beautiful if each cell has at least 33 toroidal neighbors with the same color as itself.
Two cells are considered toroidal neighbors if they toroidally share an edge. In other words, for some integers 1≤x1,x2≤n1≤x1,x2≤n and 1≤y1,y2≤m1≤y1,y2≤m, the cell in the x1x1-th row and y1y1-th column is a toroidal neighbor of the cell in the x2x2-th row and y2y2-th column if one of following two conditions holds:
- x1−x2≡±1(modn)x1−x2≡±1(modn) and y1=y2y1=y2, or
- y1−y2≡±1(modm)y1−y2≡±1(modm) and x1=x2x1=x2.
Notice that each cell has exactly 44 toroidal neighbors. For example, if n=3n=3 and m=4m=4, the toroidal neighbors of the cell (1,2)(1,2) (the cell on the first row and second column) are: (3,2)(3,2), (2,2)(2,2), (1,3)(1,3), (1,1)(1,1). They are shown in gray on the image below:
The gray cells show toroidal neighbors of (1,2)(1,2).
Is it possible to color all cells with the pigments provided and create a beautiful picture?
Input
Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041≤t≤104). The description of the test cases follows.
The first line of each test case contains three integers nn, mm, and kk (3≤n,m≤1093≤n,m≤109, 1≤k≤1051≤k≤105) — the number of rows and columns of the picture and the number of pigments.
The next line contains kk integers a1,a2,…,aka1,a2,…,ak (1≤ai≤1091≤ai≤109) — aiai is the maximum number of cells that can be colored with the ii-th pigment.
It is guaranteed that the sum of kk over all test cases does not exceed 105105.
Output
For each test case, print "Yes" (without quotes) if it is possible to color a beautiful picture. Otherwise, print "No" (without quotes).
Example
input
Copy
6 4 6 3 12 9 8 3 3 2 8 8 3 3 2 9 5 4 5 2 10 11 5 4 2 9 11 10 10 3 11 45 14
output
Copy
Yes No Yes Yes No No
Note
In the first test case, one possible solution is as follows:
In the third test case, we can color all cells with pigment 11.==========================================================================================================================================
构造题,必然是整行整列涂,很容易发现,两行或两列抱团就一定可以,大于等于两行两列也是可以的。
分别对整行涂,整列涂分情况讨论
整列涂的时候,把每种颜色能涂的最大列数算出来,计算大于等于2的总和
如果行是偶数,2 4 6 8 10...
最后发现只要合超过n就可以,由于我们都是大于等于2的,在计算合的时候,如果等于n那肯定正好,如果结果是n+1,那么一定是出现了大于等于3的奇数,把这个给扣掉就行,n+2也是同理
如果行是奇数,如果之和为n,那么一定可以且一定包含一个大于等于3的,n+1的时候,就要分情况讨论了,n+1是偶数,如果全是2那么肯定不行了,必然有一个2被我们扣掉1成为单独的,但凡有一个大于等于3的,我们就可以扣掉1,剩下的抱团组成n。n+2是奇数,如果全是大于等于3的奇数,扣掉两个不同的1,如果有一个是大于等于3的,剩下全是2,那么显然扣掉一个2就可以,且只能扣掉一个2,而且必须得有一个大于等于3的来保证是奇数。n+3也是同理
可知奇数时必须要有一个大于等于3的来维持
# include <iostream>
# include<algorithm>
# include<cstring>
# include<vector>
# include<queue>
# define mod 1000000007
using namespace std;
typedef long long int ll;
ll a[100000+10];
ll b[100000+10];
int main()
{
int t;
cin>>t;
while(t--)
{
ll n,m,k;
cin>>n>>m>>k;
int flag=0;
for(int i=1; i<=k; i++)
{
cin>>a[i];
}
if(n==1||m==1)
{
cout<<"NO"<<endl;
continue;
}
ll cnt2=0,cnt3=0;//,flag=0;
for(int i=1; i<=k; i++)
{
b[i]=a[i]/m;
if(b[i]>=2)
{
cnt2+=b[i];
if(b[i]>=3)
{
cnt3=1;
}
}
}
if(n%2==0)
{
if(cnt2>=n)
{
flag=1;
}
}
else if(n%2)
{
if(cnt2>=n)
{
if(cnt3)
flag=1;
}
}
swap(n,m);
cnt2=0,cnt3=0;
for(int i=1; i<=k; i++)
{
b[i]=a[i]/m;
if(b[i]>=2)
{
cnt2+=b[i];
if(b[i]>=3)
{
cnt3=1;
}
}
}
if(n%2==0)
{
if(cnt2>=n)
{
flag=1;
}
}
else if(n%2)
{
if(cnt2>=n)
{
if(cnt3)
flag=1;
}
}
if(flag)
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
}
}
return 0;
}边栏推荐
- 5 款漏洞扫描工具:实用、强力、全面(含开源)
- glusterfs build and use
- 分分钟教你读取 resources 目录下的文件路径
- 【kali-漏洞扫描】(2.1)Nessus下载安装(上)
- ES、Kibana 8.0安装
- DDD 中的几个困难问题
- tidyverse based on data.table?
- 解决npm -v查看npm版本出现npm WARN config global `--global`, `--local` are deprecated. Use `--location报错
- leetcode 072. Finding Square Roots
- ES6--residual parameters
猜你喜欢

Likou 59 - Spiral Matrix II - Boundary Judgment

idea2021配置svn报错Cannot run program “svn“ (in directory “xxx“):CreateProcess error=2,系统找不到指定的文件

svg+js订单确认按钮动画js特效

Cesium 修改鼠标样式

Why BI software can't handle correlation analysis

《QDebug 2022年7月》

Li Mu hands-on learning deep learning V2-BERT fine-tuning and code implementation

安全基础8 ---XSS

Engineering Effectiveness Governance for Agile Delivery

在树莓派上搭建属于自己的网页(4)
随机推荐
面试官:为什么 0.1 + 0.2 == 0.300000004?
Likou 707 - Design Linked List - Linked List
abs()、fabs() 和 labs() 的区别
Often forget HiFlow 】 【 check-in?Use tencent cloud scenario connector to remind you every day.
【kali-漏洞扫描】(2.1)Nessus解除IP限制、扫描快无结果、插件plugins被删除(中)
直播平台怎么搭建,针对输入框的各种组件
从开发到软件测试:除了扎实的测试基础,还有哪些必须掌握 ?
Zero trust, which has been popular for more than ten years, why can't it be implemented?
博士申请 | 美国明尼苏达大学葛畅教授招收隐私数据管理方向全奖博士/硕士/博后/访问学者...
解决npm -v查看npm版本出现npm WARN config global `--global`, `--local` are deprecated. Use `--location报错
ES6解构赋值--数组解构及对象解构
canvas螺旋动画js特效
9月1日起我国给予多哥等16国98%税目产品零关税待遇
Use setTimeout to realize setInterval
Orcad Capture Cadence 新建原理图多部分smybol和Homogeneous、Heterogeneous类型介绍教程
From September 1st, my country has granted zero-tariff treatment to 98% of tax items from 16 countries including Togo
leetcode 899. 有序队列
Android build error: Plugin with id ‘kotlin-android‘ not found.
Leetcode 16. Numerical integral power (power + fast recursive/iteration)
ES6-箭头函数