codeforces 357
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的更多相关文章
- 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 ...
- 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 ...
- Codeforces Round #357 (Div. 2) C. Heap Operations 模拟
C. Heap Operations 题目连接: http://www.codeforces.com/contest/681/problem/C Description Petya has recen ...
- Codeforces Round #357 (Div. 2) B. Economy Game 水题
B. Economy Game 题目连接: http://www.codeforces.com/contest/681/problem/B Description Kolya is developin ...
- Codeforces Round #357 (Div. 2) A. A Good Contest 水题
A. A Good Contest 题目连接: http://www.codeforces.com/contest/681/problem/A Description Codeforces user' ...
- 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 ...
- Codeforces Round #357 (Div. 2) E 计算几何
传说中做cf不补题等于没做 于是第一次补...这次的cf没有做出来DE D题的描述神奇 到现在也没有看懂 于是只补了E 每次div2都是hack前2~3题 终于打出一次hack后的三题了...希望以后 ...
- Codeforces Round #357 (Div. 2) 优先队列+模拟
C. Heap Operations time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces Round #357 (Div. 2) C
C. Heap Operations time limit per test 1 second memory limit per test 256 megabytes input standard i ...
随机推荐
- iOS-setNeedsLayout等布局方法
列举下iOS layout的相关方法: layoutSubviews layoutIfNeeded setNeedsLayout setNeedsDisplay drawRect sizeThatFi ...
- word页眉与页脚详解
1.如何隔离封面等不需要插入页码的页面: 首先插入分节符下一页(一定是分节符),再在下一页(即要开始插入页码的页面)选择视图-->页眉和页脚-->设置为取消链接到前一页.设置页码格式为起始 ...
- python bottle学习(四)request.quest/query_string/params/body等方法介绍
假设url:http://0.0.0.0:18082/api/cluster/group?wzd=111&abc=cc 方法类型:POST,body是{"name":& ...
- 讨论cocos2d-x字体绘制原理和应用方案
转自:http://blog.csdn.net/langresser_king/article/details/9012789 个人一直认为,文字绘制是cocos2d-x最薄弱的环节.对于愤怒的小鸟之 ...
- Less-mixin函数基础一
//mixin函数 立即执行mixin函数,example: .test{ color:#ff00000; background:red; } //立即执行mixin grammar 1 扩展exte ...
- etcd跨机房部署方案
使用ETCD做为元数据方便快捷,但是谈到跨机房灾备可能就迷糊了,我们在做节日灾备的时候同样遇到了问题, 通过查阅官方文档找到了解决方案,官方提供make-mirror方法,提供数据镜像服务 注意: m ...
- PLSQL Developer在未安装Oracle Client情况下连接Oracle
常用的Oracle开发的工具有SQL Developer和PL/SQL Developer, 用PL/SQL连接oracle数据库,不管是本地的还是远程的,一般都需要安装oracle客户端 如何达到不 ...
- Android 短信箱操作
package blackice.android.product; import java.sql.Date; import java.text.SimpleDateFormat; import ja ...
- C++ 调用webservice 出现 函数返回值为 3 (SOAP_TAG_MISMATCH) 的解决方案
最近在用C++ gsoap做webservice服务时,函数返回值为SOAP_TAG_MISMATCH (==3)错误码,原因是我传入wsdl地址时连同后面的?wsdl都传入了,如下: http:// ...
- MyISAM Key Buffer 读/写/利用率(%) MylSAM平均每秒Key Buffer利用率(%) MylSAM平均每秒Key Buffer读命中率(%) MylSAM平均每秒Key Buffer写命中率(%)
MyISAM Key Buffer 读/写/利用率(%) MylSAM平均每秒Key Buffer利用率(%)MylSAM平均每秒Key Buffer读命中率(%)MylSAM平均每秒Key Buff ...