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. package.json字段分析

    分析1.必须在包的顶层目录下2.二进制文件应该在bin目录下3.javascipt在lib目录下4.文档在doc目录下 package.json字段分析 name:包的名称,必须是唯一的,由小写英文字 ...

  2. advanced regression to predict housing prices

    https://docs.google.com/presentation/d/e/2PACX-1vQGlXP6QZH0ATzXYwnrXinJcCn00fxCOoEczPAXU-n3hAPLUfMfi ...

  3. git出现误修改如何撤销

    场景1:当你改乱了工作区某个文件的内容,想直接丢弃工作区的修改时,用命令git checkout -- file. 场景2:当你不但改乱了工作区某个文件的内容,还添加到了暂存区时,想丢弃修改,分两步, ...

  4. k8s资源配置清单的书写格式(yaml文件)

    yaml文件书写格式:5大类:apiVersion: 选择kubectl api-versions里面存在的版本kind: 选择kubectl api-resources结果中的对象资源metadat ...

  5. 配置vim nginx.conf高亮

    #!/bin/bashwget http://www.vim.org/scripts/download_script.php?src_id=14376 -O nginx.vimmv nginx.vim ...

  6. js测试密码的强度

    测试密码的强度.js //网站也会根据输入密码的字符特点给出相应的提示,如密码过短.强度差.强度中等.强度强等. //这又是怎么实现的呢?看下面代码: <input type="pas ...

  7. 微信在浏览器打开前的提示页面Android与IOS判断

    直接在网上扒一个页面,分分钟搞定!  先看一下效果 这是用微信开发工具打开的样式,直接上完整代码 <!DOCTYPE html> <html lang="en"& ...

  8. python常见概念

    1. 什么是鸭子类型? 不要检查它是不是鸭子:检查它的叫声像不像鸭子,走起路来像不像鸭子.如果走起路来像鸭子,叫起来也像鸭子,那么它就是鸭子.鸭子类型是编程语言中动态类型语言中的一种设计风格,一个对象 ...

  9. 数论:HDU1066-Last non-zero Digit in N!

    题目: Last non-zero Digit in N! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  10. 将SpringBoot默认Json解析框架jackson替换成fastjson

    步骤一:引入依赖<dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson< ...