codeforces 509B(构造,思维)
时间:2022-07-28
本文章向大家介绍codeforces 509B(构造,思维),主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
题意描述
There are n piles of pebbles on the table, the i-th pile contains a i pebbles. Your task is to paint each pebble using one of the k given colors so that for each color c and any two piles i and j the difference between the number of pebbles of color c in pile i and number of pebbles of color c in pile j is at most one.
In other words, let’s say that b i, c is the number of pebbles of color c in the i-th pile. Then for any 1 ≤ c ≤ k, 1 ≤ i, j ≤ n the following condition must be satisfied |b i, c - b j, c| ≤ 1. It isn’t necessary to use all k colors: if color c hasn’t been used in pile i, then b i, c is considered to be zero.
给每一组的石头染色,要求任意两组颜色的数量差不能超过1.
思路
观察样例可以发现,如果每个数和最小的数的差值大于k的话是无解的。对于有解的情况,我们可以先输出min个1,然后再依次输出1,2,3,…,n即可
AC代码
#include<bits/stdc++.h>
#define x first
#define y second
#define PB push_back
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) begin(a),end(a)
#define rep(x,l,u) for(ll x=l;x<u;x++)
#define rrep(x,l,u) for(ll x=l;x>=u;x--)
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<long,long> PLL;
typedef pair<char,char> PCC;
typedef long long ll;
const int N=1e5+10;
const int M=1e6+10;
const int INF=0x3f3f3f3f;
const int MOD=1e9+7;
int a[N];
void solve(){
int n,k;cin>>n>>k;
int MIN=INF;
rep(i,1,n+1){
cin>>a[i];
MIN=min(MIN,a[i]);
}
int flag=0;
rep(i,1,n+1){
if(a[i]-MIN>k) flag=1;
}
if(flag) cout<<"NO"<<endl;
else{
cout<<"YES"<<endl;
rep(i,1,n+1){
rep(j,1,MIN+1) cout<<1<<' ';
rep(j,1,a[i]-MIN+1) cout<<j<<' ';
cout<<endl;
}
}
}
int main(){
IOS;
solve();
return 0;
}
- 使用Hexo搭建专属Blog
- Android项目中文字乱码问题
- golang中发送http请求的几种常见情况
- 注册中心 Eureka 源码解析 —— Eureka-Server 启动(一)之 ServerConfig
- lua表排序
- Go语言-base64使用
- Gitcafe绑定自定义域名
- 【死磕Java并发】—- J.U.C之并发工具类:CyclicBarrier
- Android Studio快捷键
- go 切片使用小结
- 分布式事务 TCC-Transaction 源码分析 —— 项目实战
- 分布式事务 TCC-Transaction 源码分析 —— 事务恢复
- Go的语言特性总结
- 注册中心 Eureka 源码解析 —— Eureka-Client 初始化(三)之 EurekaClient
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 巧用x-cos-traffic-limit header来限制上传下载速率
- centos7上编译安装php7以php-fpm方式连接apache
- 基于Python实现视频的人脸融合功能
- 如何理解python对象
- Virtualenv 搭建 Py项目运行环境的教程详解
- python字符串的index和find的区别详解
- 浅谈Python 参数与变量
- 宝塔面板成功部署Django项目流程(图文)
- Python celery原理及运行流程解析
- Python Scrapy图片爬取原理及代码实例
- Python-for循环的内部机制
- 解决Tensorflow2.0 tf.keras.Model.load_weights() 报错处理问题
- 基于python实现模拟数据结构模型
- keras的siamese(孪生网络)实现案例
- 浅谈cv2.imread()和keras.preprocessing中的image.load_img()区别