[Codeforces 26E] MultiThreading
Brief Intro:
给你n个数,每个数有2*CNT[i]个,让你构造一个序列
使得最终的Y值为W(其余见题面)
Solution:
就是一道纯构造的题目:
先把特殊情况特殊处理,接下来考虑一般情况:
如果让每种数字都连续放置,则对于每两个相同的A[i],Y则加一
要想最终Y=W,则要将多余的去除。于是这样构造:
A:1........1211...112 B:11..122..233...344...4.....nn
最终序列分为A段和B段,其中A段仅能使Y+=2,同时去除多余的项
剩余的先计算好后在B中连续放置即可
Code:
#include <bits/stdc++.h> using namespace std; template<class T> inline void putnum(T x)
{
if(x<)putchar('-'),x=-x;
register short a[]={},sz=;
while(x)a[sz++]=x%,x/=;
if(sz==)putchar('');
for(int i=sz-;i>=;i--)putchar(''+a[i]);
putchar(' ');
} int n,w,dat[],res[],sum=,pos=-; int main()
{
cin >> n >> w;
for(int i=;i<=n;i++)
{
cin >> dat[i],sum+=dat[i];
if(dat[i]==) pos=i;
} if(w< || w>sum || (n== && w!=sum) || (w== && pos==-))
return puts("No"),;
puts("Yes"); if(n==)
for(int i=;i<=*dat[];i++) putnum();
else if(w==)
{
dat[pos]--;
putnum(pos);
for(int i=;i<=n;i++)
for(int j=;j<=*dat[i];j++)
putnum(i);
putnum(pos);
}
else
{
w=w-;dat[]--;dat[]--;
for(int i=;i<=n;i++)
while(w && dat[i])
res[i]++,w--,dat[i]--;
putnum();
for(int i=;i<=n;i++)
for(int j=;j<=*dat[i];j++)
putnum(i);
putnum();putnum();
for(int i=;i<=*dat[];i++) putnum();
putnum();
for(int i=;i<=n;i++)
for(int j=;j<=*res[i];j++)
putnum(i);
}
return ;
}
Review:
对于构造题,要利用性质去除不符合条件的项
[Codeforces 26E] MultiThreading的更多相关文章
- codeforce 270B Multithreading
B. Multithreading Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- CentOS 6通过yum升级Git
By francis_hao Mar 9,2017 在一个新机器上推送代码到github上时出现了下面的问题 error: The requested URL returned error: ...
- wget下载HTTPS链接
wget -c -O master.zip --no-check-certificate https://github.com/mitsuhiko/flask/archive/master.zip # ...
- bzoj 4836 [Lydsy1704月赛]二元运算 分治FFT+生成函数
[Lydsy1704月赛]二元运算 Time Limit: 8 Sec Memory Limit: 128 MBSubmit: 577 Solved: 201[Submit][Status][Di ...
- white-space——处理元素内的空白
定义和用法 white-space 属性设置如何处理元素内的空白.这个属性声明建立布局过程中如何处理元素中的空白符.值 pre-wrap 和 pre-line 是 CSS 2.1 中新增的. 默认 ...
- css3 新旧伸缩盒的异同
由于不需要理会IE浏览器,伸缩盒(flexible box)移动端开发中非常好用! 工作中使用APICLOUD开发手机App,老板要求兼容到安卓2.3(新版的需要安卓4.4以上),所以一直使用的是旧版 ...
- linux USB HOST之EHCI和OHCI【转】
转自:http://blog.csdn.net/ljzcom/article/details/8186914 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[-] 2 关键数据结 ...
- 【反演复习计划】【bzoj3529】数表
Orz PoPoQQQ大爷 按照他ppt的解法,这题可以划归到之前的题了OrzOrz 跪wy写的题解(Stealth Assassin)https://www.luogu.org/wiki/show? ...
- string与double的互相转换
#include <iostream> #include <string> #include <sstream> string DoubleToString(dou ...
- go语言实现拷贝文件
package main import ( "fmt" "io" "os" ) func main(){ list := os.Args / ...
- selenium 滚动条操作(JavaScript操作)
前言 一般我们想到的必须使用滚动条的场景是:注册时的法律条文的阅读.判断用户是否阅读完的标准是:滚动条是否拉到页面底部.当然,有时候为使操作更接近用户行为也会使用滚动条,例如用户要操作的元素在页面的第 ...