C 题意:

###n个勇士编号1-n,m个回合对战,每个回合由仍留在游戏里的编号Li~Ri的人参加,胜者为Xi,输的人退出游戏。

###求一个a1-an的序列,若ai为胜者,则ai=0,否则ai=打败ai的勇士的编号。

 思路:

  解法一:使用set,输的人擦除。

#include<bits/stdc++.h>
using namespace std;
set<int> s;
set<int>::iterator it,lp;
int ans[]={},del[];
int main() {
int n,m,l,r,win;
scanf("%d%d",&n,&m);
for(int i=;i<=n;++i) s.insert(i);
while(m--) {
scanf("%d%d%d",&l,&r,&win);
lp=s.lower_bound(l);
int cnt=;
for(it=lp;*it<=r&&it!=s.end();++it) {
if(*it==win) continue;
ans[*it]=win;
del[cnt++]=*it;
}
for(int i=;i<cnt;++i) {
s.erase(del[i]);
}
}
for(int i=;i<=n;++i) {
printf("%d ",ans[i]==i?:ans[i]);
}
return ;
}

D 题意:http://codeforces.com/problemset/problem/357/D

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=;
char a[maxn],b[maxn];
ll cnt[maxn][]={};
ll gcd(ll x, ll y) {
return y==?x:gcd(y,x%y);
}
int main() {
ll n,m,g,alen,blen,len,ans=;
scanf("%I64d%I64d",&n,&m);
scanf("%s%s",a,b);
alen=strlen(a);
blen=strlen(b);
g=gcd(alen,blen);
len=alen*blen/g; for(int i=;i<alen;++i)
++cnt[i%g][a[i]-'a']; for(int i=;i<blen;++i)
ans+=cnt[i%g][b[i]-'a']; ans=n*alen-n*alen/len*ans;
printf("%I64d\n",ans);
return ;
}

E 题意:有n个车厢,每个车厢有4个人,其中ai个学生,交换最少的人使得每个车厢的学生数为0或3或4,无法达成输出-1。

思路:贪心。统计车厢内学生为1,2,3,4的数目cnt[1],cnt[2],cnt[3],cnt[4]。

  目标为最少的步数,过程中应先配出cnt[3],配不出3时考虑4。

  首先考虑cnt[1]不为0时,尽可能让cnt[1]与cnt[2]配对,这样可以同时减少cnt[1]与cnt[2]的数目使二者符合要求,明显最优,即1 2 -> 3。

  然后考虑让三个1抱团 1 1 1 -> 3 ;剩下一个1时考虑 1 3 -> 4;剩下两个1时先考虑1 1 3 3 -> 4 4 ,再考虑1 1 -> 2。

  这些过程后若cnt[1]!=0,则无解。

  考虑cnt[2]不为0时,2 2 2 -> 3 3;剩下一个2时先考虑 2 4 -> 3 3,再考虑 2 3 3 ->  4 4;剩下两个2时考虑 2 2 -> 4。

#include<bits/stdc++.h>
using namespace std;
int cnt[]={};
int main() {
int n,x,ans=,t;
scanf("%d",&n);
for(int i=;i<n;++i) {
scanf("%d",&x);
++cnt[x];
}
if(!cnt[]&&!cnt[]) {
puts("");
return ;
}
if(cnt[]) {
if(cnt[]) { // 1 2 -> 3
t=min(cnt[],cnt[]);
ans+=t;
cnt[]-=t;
cnt[]-=t;
cnt[]+=t;
}
if(cnt[]) {
       // 1 1 1 -> 3
ans+=cnt[]/*;
cnt[]+=cnt[]/;
cnt[]%=;
if(cnt[]==) {
if(cnt[]>=) ans+=,cnt[]-=,cnt[]+=; // 1 1 3 3 -> 4 4
else ++ans,++cnt[]; // 1 1 -> 2
}
else if(cnt[]==) {
if(cnt[]) ++ans,--cnt[],++cnt[]; // 1 3 -> 4
else if(cnt[]&&cnt[]<) {
puts("-1");
return ;
}
else cnt[]-=,ans+=2,cnt[3]+=3; // 1 4 4 -> 3 3 3
}
cnt[]=;
}
}
if(cnt[]) {
     // 2 2 2 -> 3 3
ans+=cnt[]/*;
cnt[]+=cnt[]/*;
cnt[]%=;
if(cnt[]==) ans+=,cnt[]=,++cnt[]; // 2 2 -> 4
else if(cnt[]==) {
if(cnt[]) ++ans,cnt[]=,--cnt[],cnt[]+=; // 2 4 -> 3 3
else if(cnt[]>=) ans+=,cnt[]=,cnt[]-=,cnt[]+=; // 2 3 3 -> 4 4
else {
puts("-1");
return ;
}
}
}
if(!cnt[]&&!cnt[]) printf("%d\n",ans);
else puts("-1");
return ;
}

codeforces 357的更多相关文章

  1. Codeforces Round #357 (Div. 2) E. Runaway to a Shadow 计算几何

    E. Runaway to a Shadow 题目连接: http://www.codeforces.com/contest/681/problem/E Description Dima is liv ...

  2. Codeforces Round #357 (Div. 2) D. Gifts by the List 水题

    D. Gifts by the List 题目连接: http://www.codeforces.com/contest/681/problem/D Description Sasha lives i ...

  3. Codeforces Round #357 (Div. 2) C. Heap Operations 模拟

    C. Heap Operations 题目连接: http://www.codeforces.com/contest/681/problem/C Description Petya has recen ...

  4. Codeforces Round #357 (Div. 2) B. Economy Game 水题

    B. Economy Game 题目连接: http://www.codeforces.com/contest/681/problem/B Description Kolya is developin ...

  5. Codeforces Round #357 (Div. 2) A. A Good Contest 水题

    A. A Good Contest 题目连接: http://www.codeforces.com/contest/681/problem/A Description Codeforces user' ...

  6. Codeforces Round #357 (Div. 2) A

    A. A Good Contest time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  7. Codeforces Round #357 (Div. 2) E 计算几何

    传说中做cf不补题等于没做 于是第一次补...这次的cf没有做出来DE D题的描述神奇 到现在也没有看懂 于是只补了E 每次div2都是hack前2~3题 终于打出一次hack后的三题了...希望以后 ...

  8. Codeforces Round #357 (Div. 2) 优先队列+模拟

    C. Heap Operations time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  9. Codeforces Round #357 (Div. 2) C

    C. Heap Operations time limit per test 1 second memory limit per test 256 megabytes input standard i ...

随机推荐

  1. RadioButton ---- 样式效果切换

    \res\drawable\radio_button_bg.xml <?xml version="1.0" encoding="utf-8"?> & ...

  2. Java Base64解析

    最近在业务场景中,需要对第三方传递进来的字符进行base64解密,根据第三方文档提供的解析工具,对数据进行了解析,关于Base64的解析方式如下: String sign = "xxxxxx ...

  3. cdr X6 64位32位缩略图补丁包

    cdr X6 64位32位缩略图补丁包下载 安装了X6没有缩略图的话,点击下面链接下载安装插件即可 点击下载

  4. golang 热更新技巧 负载均衡才是正道啊

    golang plugin热更新尝试 - 呵大官人的鱼塘 - 开源中国 https://my.oschina.net/scgywx/blog/1796358 golang plugin热更新尝试 发布 ...

  5. Ansi、GB2312、GBK、Unicode(utf8、16、32)

    关于ansi,一般默认为本地编码方式,中文应该是gb编码 他们之间的关系在这边文章里描写的很清楚:http://blog.csdn.net/ldanduo/article/details/820353 ...

  6. ubuntu14 编译安装(升级)g++

    编译安装(升级)g++ ubuntu14自带的g++为4.8.4,不支持c++11.现要将g++升至5.2.0 1.下载安装: 参考https://www.cppfans.org/1719.html ...

  7. 详解Bootstrap下拉菜单组件

    bootstrap框架中的下拉菜单组件是一个独立的组件,根据不同的版本,他对应的文件: less 对应的源码文件为:dropdowns.less sass对应的源码文件为:_dropdowns.scs ...

  8. Android安装APK报错:Installation error: INSTALL_FAILED_UPDATE_INCOMPATIBLE解决方法

    今天调试一个android应用的时候,安装报了Installation error: INSTALL_FAILED_UPDATE_INCOMPATIBLE错误,代码如下: [2015-12-28 15 ...

  9. Leetcode 之 Kth Largest Element in an Array

    636.Kth Largest Element in an Array 1.Problem Find the kth largest element in an unsorted array. Not ...

  10. java-序列化-001-原生介绍

    一.什么是对象序列化 java平台允许我们在内存中创建可复用的Java对象,但一般情况下,只有当JVM处于运行时,这些对象才可能存在,即,这些对象的生命周期不会比JVM的生命周期更长.但在现实应用中, ...