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的更多相关文章

  1. codeforce 270B Multithreading

    B. Multithreading Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss ...

  2. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  3. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  4. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  5. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  6. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  7. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  8. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

  9. CodeForces - 696B Puzzles

    http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...

随机推荐

  1. js生成图片

    var image = new Image(); var c = document.getElementById("myCanvas"); var ctx = c.getConte ...

  2. [poj 1947]树dp+背包问题

    题目链接:http://poj.org/problem?id=1947 看了很多题解都是直接一遍dfs就搞定的方法,但是我实在是没看懂那个转移方程.最后在茫茫博客中终于发现了一个有逻辑的方法,但是复杂 ...

  3. IDEA 使用maven创建web项目,打包war时不会创建class文件

    使用maven创建项目后我有创建了个src的目录,导致maven编译不能识别我创建的src文件下的Java文件 修改这样后就可以识别编译Java文件 今天又给自己挖了个坑.......

  4. TypeScript+Vue初体验Demo

    github: https://github.com/lanleilin/Typescript-Vue-Demo

  5. Nim博弈(nim游戏)

    http://blog.csdn.net/qiankun1993/article/details/6765688 NIM 游戏 重点结论:对于一个Nim游戏的局面(a1,a2,...,an),它是P- ...

  6. 【Foreign】远行 [LCT]

    远行 Time Limit: 20 Sec  Memory Limit: 256 MB Description Input Output Sample Input 0 5 10 1 4 5 2 3 2 ...

  7. 【BZOJ 3907】网格(Catalan数)

    题目链接 这个题推导公式跟\(Catalan\)数是一样的,可得解为\(C_{n+m}^n-C_{n+m}^{n+1}\) 然后套组合数公式\(C_n^m=\frac{n!}{m!(n-m)!}\) ...

  8. 安装l Xposed Framework

    How to install Xposed Framework on Android 4.x.x :   1. For Android 4.0.3 through 4.4.4 Visit this X ...

  9. (转)自动安装VIM插件

    转自: http://xwz.me/wiki/doku.php?id=vim:plugins 我的插件列表 把下面GetLatestVimScripts.dat放进~/.vim/GetLatest/目 ...

  10. linux 系统函数之 (dirname, basename)【转】

    转自:http://blog.csdn.net/peter_cloud/article/details/9308333 版权声明:本文为博主原创文章,未经博主允许不得转载. 除非你的原件考虑跨平台. ...