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. 自己搭建v,p,n过程

    安装dockeryum install -y docker把docker设置为服务systemctl enable docker.service启动dockersystemctl start dock ...

  2. iOS 计算某个月的天数 计算某天的星期

    // 某年某月的天数 - (NSInteger)dayCount:(NSInteger)years { NSInteger count = ; ; i <= ; i++) { == i) { = ...

  3. 巨蟒python全栈开发flask8 MongoDB回顾 前后端分离之H5&pycharm&夜神

    1.MongoDB回顾 .启动 mongod - 改变data/db位置: --dbpath D:\data\db mongod --install 安装windows系统服务 mongod --re ...

  4. php 正则表达式三.模式修正

    1.贪婪模式和懒惰模式, 贪婪模式:php中正则默认是贪婪模式,匹配尽可能多 的字符,比如 $pattern='/a+b/'; $subject='aaaaaaaaab,那么可能会preg_match ...

  5. CSDN2015博客之星评选之拉票环节

    最近接到CSDN邀请,参加了CSDN 2015博客之星 的评选活动,下面是给我拉票的链接地址: http://vote.blog.csdn.net/blogstar2015/candidate?use ...

  6. Cocos2dx3.1-Android环境搭建初体验

    初玩Cocos2dx,多多包涵. 感觉版本号之间的差异比較大.相对前面的版本号来说.3.X更easy上手.更方便了. 一.安装python.我的python-2.7.3. 配置环境变量 系统变量里:在 ...

  7. linux环境配置时钟同步ntpd服务

    配置: 服务器1:192.168.169.139 服务器2:192.168.169.140 服务器3:192.168.169.141 目的:NTP能与互联网的时间保持同步,而且本身也是一台NTP服务器 ...

  8. PL/SQL编程—包

    1.PLSQL 中的包就相当于java中的package,主要好处有(1)防止命名污染,(2)功能统一,(3)允许重载,(4)可以隐藏核心代码,(5)最重要的就是断开依赖链. 2.对于一个程序需要大量 ...

  9. Linux信号signal处理机制

    信号机制是进程之间相互传递消息的一种方法,信号全称为软中断信号,也有人称作软中断.从它的命名可以看出,它的实质和使用很象中断.所以,信号可以说是进程控制的一部分.         一.信号的基本概念 ...

  10. Google ProtocolBuffer

    https://www.ibm.com/developerworks/cn/linux/l-cn-gpb/index.html 1. Protocol Buffers 简介 Protocol Buff ...