2017.2.26 CF D2 402

这次状态还算能忍吧……一路不紧不慢切了前ABC(不紧不慢已经是在作死了),卡在D,然后跑去看E和F——卧槽怎么还有F,早知道前面做快点了……

F看了看,不会,弃

E看了看,不会,弃

D看了看,不会……没法再弃了。想了好久发现可以二分答案(浪费30min)

过了D以后去看F,发现果然还是不会(浪费20min)

之后看E,思路跑偏浪费20min+

此时时间还剩大约20min,终于想到了E可能是正解的做法,开始拼手速,各种调试,终于调过了样例,而时间只剩10s了……试图提交,拼手速成功,拼网速失败……

1000+分的差距,有时候只有几秒钟(其实是SX博主前面浪费太多时间,活该)

↑比赛结束后交了一发E,1A,这就更气了……

A.Pupils Redistribution

如果分数为x的学生数为奇数,那么无解。

否则把多于平均数量的学生给对面,累计答案

那个cnt似乎没必要

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*-''+ch;ch=getchar();}
return x*f;
}
int a[mxn],b[mxn];
int cnt=;
int main(){
int i,j,x;
int n=read();
for(i=;i<=n;i++){
x=read();
a[x]++;
}
for(i=;i<=n;i++){
x=read();
b[x]++;
}
int ans=;
for(i=;i<=;i++){
if((a[i]+b[i])&){
printf("-1\n");
return ;
}
cnt+=(a[i]-(a[i]+b[i])/);
ans+=abs((a[i]-(a[i]+b[i])/));
}
if(cnt)printf("-1\n");
else{
printf("%d\n",ans/);
}
return ;
}

A

B.Weird Rounding

问至少删几个数字可以使得剩下的数能被10的k次方整除

暴力模拟,从尾部开始删。

注意特判只留一个0的情况。

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#define LL long long
using namespace std;
const int mxn=;
LL read(){
LL x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*-''+ch;ch=getchar();}
return x*f;
}
LL n;int k;
int ans;
int main(){
int i,j;
n=read();k=read();
LL tmp=n;
int len=;
while(tmp){
tmp/=;
len++;
}
ans=len-;
tmp=n;
len=;
bool flag=;
while(tmp){
if(tmp%==)k--,flag=;
else len++;
if(!k)break;
tmp/=;
}
if(k)len=1e8;
if(k&&flag)ans++;
printf("%d\n",min(ans,len));
return ;
}

B

C.Dishonest Sellers

贪心?

现在至少买k件物品,剩下的在打折结束后买,问最小花费。

排个序,把现在买收益最大的至少k个买了,剩下的决策何时买

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*-''+ch;ch=getchar();}
return x*f;
}
struct node{
int a,b,c;
}t[mxn];
int cmp(node x,node y){
return x.c<y.c;
}
int n,k;
int main(){
int i,j;
n=read();k=read();
for(i=;i<=n;i++){
t[i].a=read();
}
for(i=;i<=n;i++){
t[i].b=read();
t[i].c=t[i].a-t[i].b;
}
sort(t+,t+n+,cmp);
int ans=;
for(i=;i<=k;i++){
ans+=t[i].a;
}
for(i=k+;i<=n;i++){
ans+=min(t[i].a,t[i].b);
}
printf("%d\n",ans);
return ;
}

C

D.String Game

求最多的取字母次数使得剩下的串中包含目标串

二分取的次数……

我可能是思路太差……见二分答案的题老是看不出来。

花了好久才想起来二分答案,接着分分钟写完

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*-''+ch;ch=getchar();}
return x*f;
}
int f[mxn];
char s[mxn],c[mxn];
int t[mxn];
int ls,lc;
bool solve(int lim){
int hd=;
for(int i=;i<=ls;i++){
if(t[i]<=lim)continue;
if(s[i]==c[hd])hd++;
if(hd>lc)return ;
}
return ;
}
int main(){
int i,j,x;
scanf("%s%s",s+,c+);
ls=strlen(s+);
lc=strlen(c+);
memset(f,0x3f,sizeof f);
f[]=0x3f3f3f3f;
for(i=;i<=ls;i++){
x=read();
t[x]=i;
}
int l=,r=ls,ans=;
while(l<=r){
int mid=(l+r)>>;
if(solve(mid)){
ans=mid;
l=mid+;
}
else r=mid-;
}
printf("%d\n",ans);
return ;
}

D

E.Bitwise Formula

字符串处理稍有点麻烦,本质是个贪心问题。

刚开始思路完全跑偏了,写了各种递归,超复杂,半天调不对(估计对了也会T),浪费了半小时

后来发现每个式子中的变量在之前都已经出现了,并且式子中不会出现 [变量 运算 数字]的格式(根本没有好好读题嘛)

@NOI2014 T1 起床困难综合征

把“?”看作第一个出现的变量,依次确定每一位是0还是1←暴力从前到后所有的式子,在"?"确定的情况下后面的变量都能被依次算出来,看"?"的这一位取0还是1可以使得结果中1最多(答案最大)。

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
using namespace std;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*-''+ch;ch=getchar();}
return x*f;
}
struct edge{
int v,nxt,op;
}e[mxn<<];
int hd[mxn],mct=;
void add_edge(int u,int v,int op){
e[++mct].v=v;e[mct].nxt=hd[u];e[mct].op=op;hd[u]=mct;return;
}
//
struct node{
string num;
int p1,p2;
int op;
}t[]; //
int f[][];
int pre[];
int op[];
map<string,int>mp;
int cnt=;
int n,m;
string s;
string cut(int st){
string tmp;tmp.clear();
int len=s.size();
for(int i=st;i<len;i++){
if(s[i]==' ')break;
tmp+=s[i];
}
return tmp;
}
int tst(int id){
int res=;
// printf("id:%d f1:%d\n",id,f[1][id]);
for(int i=;i<=cnt;i++){
// printf("i:%d op:%d p1:%d p2:%d\n",i,t[i].op,t[i].p1,t[i].p2);
if(t[i].op==-){
// printf("num:%d\n",f[i][id]);
}
else{
if(t[i].op==){
f[i][id]=f[t[i].p1][id]|f[t[i].p2][id];
}
if(t[i].op==){
f[i][id]=f[t[i].p1][id]^f[t[i].p2][id];
}
if(t[i].op==){
f[i][id]=f[t[i].p1][id]&f[t[i].p2][id];
}
}
// printf(" %d\n",f[i][id]);
if(f[i][id]==)res++;
}
// printf("res:%d\n",res);
return res;
}
int minif[],mxf[];
int main(){
int i,j;
n=read();m=read();
memset(op,-,sizeof op);
mp["?"]=++cnt;
for(i=;i<=n;i++){
getline(cin,s);
// cout<<s<<endl;
int st=,len=s.length();
//
string c=cut(st);
// cout<<c<<endl;
if(!mp[c])mp[c]=++cnt;
st+=c.length()+;
string tmp=cut(st);
// cout<<tmp<<endl;
st+=tmp.length()+;
// if(s.find("XOR")!=string::npos){//
t[mp[c]].op=;
string c1=cut(st);
st+=c1.length()+;
st+=;
string c2=cut(st);
t[mp[c]].p1=mp[c1];
t[mp[c]].p2=mp[c2];
}
else if(s.find("OR")!=string::npos){//
t[mp[c]].op=;
string c1=cut(st);
// cout<<c1<<endl;
st+=c1.length()+;
st+=;
string c2=cut(st);
t[mp[c]].p1=mp[c1];
t[mp[c]].p2=mp[c2];
}
else if(s.find("AND")!=string::npos){//
t[mp[c]].op=;
string c1=cut(st);
st+=c1.length()+;
st+=;
string c2=cut(st);
t[mp[c]].p1=mp[c1];
t[mp[c]].p2=mp[c2];
}
else if(s.find("") || s.find("")){
t[mp[c]].op=-;
string c1=cut(st);
// cout<<c1<<endl;
t[mp[c]].num=c1;
int len=c1.length();int v=mp[c];
for(j=;j<len;j++){
f[v][j]=c1[len-j-]-'';
}
}
} for(i=;i<m;i++){
f[][i]=;
int t1=tst(i);
f[][i]=;
int t2=tst(i);
if(t1<t2){
minif[i]=;
mxf[i]=;
}
else if(t1==t2){
minif[i]=;
mxf[i]=;
}
else{
minif[i]=;
mxf[i]=;
}
}
for(i=m-;i>=;i--)printf("%d",minif[i]);
printf("\n");
for(i=m-;i>=;i--)printf("%d",mxf[i]);
return ;
}

E

差1分钟就能进rank100了,那叫一个气

这个时候只有我的过气女团能安慰我了

CodeForces Round #402 (Div.2) A-E的更多相关文章

  1. Codeforces Round #402 (Div. 2)

    Codeforces Round #402 (Div. 2) A. 日常沙比提 #include<iostream> #include<cstdio> #include< ...

  2. Codeforces Round #402 (Div. 2) A+B+C+D

    Codeforces Round #402 (Div. 2) A. Pupils Redistribution 模拟大法好.两个数列分别含有n个数x(1<=x<=5) .现在要求交换一些数 ...

  3. Codeforces Round #402 (Div. 2) A,B,C,D,E

    A. Pupils Redistribution time limit per test 1 second memory limit per test 256 megabytes input stan ...

  4. Codeforces Round #402 (Div. 2) D. String Game

    D. String Game time limit per test 2 seconds memory limit per test 512 megabytes input standard inpu ...

  5. Codeforces Round #402 (Div. 2) A B C sort D二分 (水)

    A. Pupils Redistribution time limit per test 1 second memory limit per test 256 megabytes input stan ...

  6. 【DFS】Codeforces Round #402 (Div. 2) B. Weird Rounding

    暴搜 #include<cstdio> #include<algorithm> using namespace std; int n,K,Div=1,a[21],m,ans=1 ...

  7. Codeforces Round #402 (Div. 2) 题解

    Problem A: 题目大意: 给定两个数列\(a,b\),一次操作可以交换分别\(a,b\)数列中的任意一对数.求最少的交换次数使得任意一个数都在两个序列中出现相同的次数. (\(1 \leq a ...

  8. Codeforces Round #402 (Div. 2) 阵亡记

    好长时间没有打Codeforces了,今天被ysf拉过去打了一场. lrd也来参(nian)加(ya)比(zhong)赛(sheng) Problem A: 我去,这不SB题吗.. 用桶统计一下每个数 ...

  9. Codeforces Round #402 (Div. 2) B

    Description Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k. ...

随机推荐

  1. ceph 性能

    mysql在以下设备备份耗时,供大家参考: 备份文件大小 sata用时 ceph用时 nas挂载sata盘用时 7G   1分钟   15G   2分钟 21分钟 47G   8分钟 82分钟 274 ...

  2. Apache 查找httpd.conf文件

    Linux下查找httpd.conf文件 $ find / -name httpd.conf  

  3. 使用eclipse导入web项目

    第一步 第二步 第三步 第四步 最后就多了一个web项目

  4. 笔记1 python入门学习笔记

    目录 官方手册 菜鸟站手册地址: python的运行方法 注释 小技巧: input()接收用户输入的内容(默认为字符串) print() 运算符 is 是判断两个标识符是不是引用自一个对象 all和 ...

  5. 对数据仓库Hive的一些认识

    首先我们得明白什么是数据仓库?   数据仓库,英文名称为Data warehouse,可简写为DW或DWH.数据仓库的目的是构建面向分析的集成化数据环境,为企业提供决策支持(Decision Supp ...

  6. Diycode开源项目 BaseApplication分析+LeakCanary第三方+CrashHandler自定义异常处理

    1.BaseApplication整个应用的开始 1.1.看一下代码 /* * Copyright 2017 GcsSloop * * Licensed under the Apache Licens ...

  7. 商品评分效果JavaScript

    <script> window.onload=function(){ //----------选中的星星会多出一个属性:isClick="true" 藉此来获取评分-- ...

  8. TCP/IP网络编程之地址族与数据序列

    分配IP地址和端口号 IP是Internet Protocol(网络协议)的简写,是为收发网络数据而分配给计算机的值.端口号并非赋予计算机的值,而是为区分程序中创建的套接字而分配给套接字的序号 网络地 ...

  9. Django基础之数据库与ORM

    一.数据库配置 1.django默认支持sqlite,mysql, oracle,postgresql数据库. django默认使用sqlite的数据库,默认自带sqlite的数据库驱动 , 引擎名称 ...

  10. ASP.NET下调用ffmpeg与mencoder实现视频转换截屏

    最近要做一个视频播放的系统,用到了ffmpeg和mencoder两个工具,查了一些资料,发现这方面的资料还挺多的,但是就是乱了一点,我自己从头整理了一下,和大家分享一下: 1.ffmpeg实现视频(a ...