CodeForces Round #402 (Div.2) A-E
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,这就更气了……
如果分数为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
问至少删几个数字可以使得剩下的数能被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
贪心?
现在至少买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
求最多的取字母次数使得剩下的串中包含目标串
二分取的次数……
我可能是思路太差……见二分答案的题老是看不出来。
花了好久才想起来二分答案,接着分分钟写完
#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
字符串处理稍有点麻烦,本质是个贪心问题。
刚开始思路完全跑偏了,写了各种递归,超复杂,半天调不对(估计对了也会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的更多相关文章
- Codeforces Round #402 (Div. 2)
Codeforces Round #402 (Div. 2) A. 日常沙比提 #include<iostream> #include<cstdio> #include< ...
- Codeforces Round #402 (Div. 2) A+B+C+D
Codeforces Round #402 (Div. 2) A. Pupils Redistribution 模拟大法好.两个数列分别含有n个数x(1<=x<=5) .现在要求交换一些数 ...
- 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 ...
- 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 ...
- 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 ...
- 【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 ...
- Codeforces Round #402 (Div. 2) 题解
Problem A: 题目大意: 给定两个数列\(a,b\),一次操作可以交换分别\(a,b\)数列中的任意一对数.求最少的交换次数使得任意一个数都在两个序列中出现相同的次数. (\(1 \leq a ...
- Codeforces Round #402 (Div. 2) 阵亡记
好长时间没有打Codeforces了,今天被ysf拉过去打了一场. lrd也来参(nian)加(ya)比(zhong)赛(sheng) Problem A: 我去,这不SB题吗.. 用桶统计一下每个数 ...
- Codeforces Round #402 (Div. 2) B
Description Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k. ...
随机推荐
- 通过Tcode查找Badi或者客户出口
https://wiki.scn.sap.com/wiki/display/ABAP/Code+To+Find+BAdi Created by Naresh Reddy K, last modifie ...
- python实现批量修改文件名
import os def dele(): # 设置一个计数器 n=0 st = input('请输入你要删除的字符:') for i in f: b = f[n] if st in b: oldna ...
- 五、MySQL 创建数据库
MySQL 创建数据库 我们可以在登陆 MySQL 服务后,使用 create 命令创建数据库,语法如下: CREATE DATABASE 数据库名; 以下命令简单的演示了创建数据库的过程,数据名为 ...
- Redux百行代码千行文档
接触Redux不过短短半年,从开始看官方文档的一头雾水,到渐渐已经理解了Redux到底是在做什么,但是绝大数场景下Redux都是配合React一同使用的,因而会引入了React-Redux库,但是正是 ...
- ZendFramework-2.4 源代码 - 关于MVC - View层 - 控制器返回值
<?php class ReturnController extends AbstractActionController { public function returnAction() { ...
- 震惊!几道Python 理论面试题,Python面试题No18
本面试题题库,由公号:非本科程序员 整理发布 第1题: 简述解释型和编译型编程语言? 解释型语言编写的程序不需要编译,在执行的时候,专门有一个解释器能够将VB语言翻译成机器语言,每个语句都是执行的时候 ...
- python3:判断手机的亮屏状态
在用python对手机做一些自动化操作时,常常会判断手机的亮屏状态,知晓手机的亮屏状态后才好做进一步的动作,如给屏幕解锁等. 用于了解手机的亮屏情况,有一个adb命令可用: adb shell du ...
- python-字符串数据类型内置方法
字符串类型内置方法 (str) 用途:描述性质的东西,如人的名字.单个爱好.地址.国家等 定义:使用单引号(' ').双引号(" ").三单引号(''' ''').三双引号(&qu ...
- Computer HDU - 2196
Computer HDU - 2196 A school bought the first computer some time ago(so this computer's id is 1). Du ...
- 爬山算法 | Java版HA_TSP
嗯哼,今天记录下采用Java编写的爬山算法(Hill Algorithm)求解TSP问题. 爬山算法与其他智能算法类似,是一种用来求解多峰函数最值的算法,爬山算法的基本思想是新解不劣于当前解则转移,否 ...