CF 1088(A , B , C , D)——思路
http://codeforces.com/contest/1088
A:Ehab and another construction problem
输出 2 和 n(偶数的话)或者 2 和 n-1(奇数的话)就行了。n==1的时候非法。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int x;
int main()
{
scanf("%d",&x);
if(x==)puts("-1");
else if(x&)printf("%d %d\n",x-,);
else printf("%d %d\n",x,);
return ;
}
B:Ehab and subtraction
排序之后走一遍就行了。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e5+;
int n,k,a[N];
int main()
{
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++)scanf("%d",&a[i]);
sort(a+,a+n+); int p=,tag=;
for(int i=;i<=k;i++)
{
if(p>n){puts("");continue;}
printf("%d\n",a[p]-tag);tag=a[p];
for(p++;a[p]==tag&&p<=n;p++);
}
return ;
}
C:Ehab and a 2-operation task
如果升序的话,比如要弄成 0 , 1 , 2 , 3 , ... n-1 , k(k>=n),假设正在做第 i 个位置,那么模数应该大于 i-1 ,如果之前都弄好了的话,这次取模就不会对之前造成影响了!
所以一开始给每个位置加上足够大的数(让它的值 >= (i-1)*2+1),然后依次取模就行了。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
int n,a[N],tag;
int main()
{
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%d",&a[i]),tag=max(tag,(i-<<)+-a[i]);
scanf("%d",&a[n]);tag=max(tag,n--a[n]);
if(tag)printf("%d\n1 %d %d\n",n,n,tag);
else printf("%d\n",n-);
for(int i=;i<n;i++)
{
printf("2 %d %d\n",i,a[i]+tag-(i-));
}
return ;
}
D:Ehab and another another xor problem
因为最高位对大小影响比较大,所以从高到低位做;这样能已经知道更高位的值,从而通过异或把更高位的影响消掉。
然后就不太会了。想着在每一位上判断 0 , 0 和 1 , 1 ,但无法通过2次来确定相等的话是同为0还是同为1。
看了题解。原来是一开始先判一个 0 , 0 来了解哪个比较大;然后可以每一位判断 0 , 1 和 1 , 0 ,这样可以知道相等的话是同为0还是同为1,但无法知道不相等的话哪个是0哪个是1;这时只要利用一开始判断出来的那个“哪个比较大”就能知道这一位上哪个是0哪个是1了!而且在判这一位的 0 , 1 和 1 , 0 时已经可以知道去掉这一位之后哪个比较大,就可以做下去了!
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
int bin[N],a,b;
int main()
{
bin[]=;for(int i=;i<;i++)bin[i]=bin[i-]<<;
printf("? 0 0\n");fflush(stdout);
int d; scanf("%d",&d);
for(int t=,x,y;t>=;t--)
{
printf("? %d %d\n",a|bin[t],b);fflush(stdout);
scanf("%d",&x);
printf("? %d %d\n",a,b|bin[t]);fflush(stdout);
scanf("%d",&y);
if(x==y)
{
if(d==)a|=bin[t]; else b|=bin[t];
d=x;
}
else if(y==)a|=bin[t],b|=bin[t];
}
printf("! %d %d\n",a,b);
return ;
}
CF 1088(A , B , C , D)——思路的更多相关文章
- CF Gym 100463B Music Mess (思路)
好题,当时想了半个小时,我往图论方面去想了,把出现过的字符串当场点,然后相互连边,那么就构成了一个三角形,一个大于三个点的连通分量里有以下结论:度为二的点可能是track,度为大于二的点一定不是tra ...
- CF 1036B Diagonal Walking v.2——思路
题目:http://codeforces.com/contest/1036/problem/B 比赛时只能想出不合法的情况还有走到终点附近的方式. 设n<m,不合法就是m<k.走到终点方式 ...
- 51nod1088(最长回文子串)
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1088 题意: 中文题目诶~ 思路: 这道题字符串长度限定为1 ...
- WC游记
第一次来WC,感觉这种集训真吼啊 day0 火车上快速补习了莫队,和AC自动姬,AC自动姬以前就会写只不过太久没写忘了我会了= = 莫队只是学习了做法,还没有做过题…… 本来想再复习一下后缀数组,然后 ...
- 重庆市队选拔 CQOI2015 解题报告
文章链接:http://www.cnblogs.com/Asm-Definer/p/4434601.html 题目链接:http://pan.baidu.com/s/1mgxIKli 官方数据:htt ...
- CF 949D Curfew——贪心(思路!!!)
题目:http://codeforces.com/contest/949/problem/D 有二分答案的思路. 如果二分了一个答案,首先可知越靠中间的应该大约越容易满足,因为方便把别的房间的人聚集过 ...
- CF 949C Data Center Maintenance——思路+SCC
题目:http://codeforces.com/contest/949/problem/C 可以想到可能是每组c有连边的可能. 但别直接给c1.c2连边,那样之后会变得很不好做. 可以把一些限制放在 ...
- CF Gym 100187A Potion of Immortality (思路,最坏情况的最小损失)
根据兔子试药情况可以缩小范围,如果死了,不在试过的药里面,如果活着,在试过的药里. 最糟的情况: 两个原则 1.能确定魔药所在的范围的尽量大,2.死得兔子尽量多. 如果当前不知道情况的药n为k的二倍以 ...
- CF 809 D Hitchhiking in the Baltic States —— 思路+DP(LIS)+splay优化
题目:http://codeforces.com/contest/809/problem/D 看题解,抄标程...发现自己连 splay 都快不会写了... 首先,题目就是要得到一个 LIS: 但与一 ...
随机推荐
- java基础(4)--运算符及表达式
运算符及表达式 算数运算 加(+) 减(-) 乘(*) 除(/) 取余(%) 自增(++) 自减(- -) 注意点 1. 同种类型参与运算(可能需要自动类型转换),返回同种类型 2. 整数的除法是整 ...
- infa dos命令
informatica8.6用dos命令执行作业的命令: pmcmd startworkflow -sv integration -d Domain_BlueBreezeq -u Administra ...
- java中Vector类的常用方法
Vector类是实现List接口,所以继承的方法就不在这里讲了 https://www.cnblogs.com/xiaostudy/p/9503199.html public void add(int ...
- PAT1042. Shuffling Machine (20)
#include <iostream> #include <vector> using namespace std; int n; string card[54]={" ...
- Linux嵌入式 -- 内核简介(x86)
0. 嵌入式系统 以应用为中心,软硬件可裁剪,对功耗.对体积.对成本等都有严格要求的专用计算机系统. 1. linux体系结构 2. 为什么 划分为 用户空间 和 内核控件 ? 分两级,内核和应用 ...
- Eclipse和MyEclipse的区别
翻译:日食,月食. eclipse是免费的,myeclipse是收费的. myeclipse是eclipse的插件.
- chrome浏览器经常无响应
chrome浏览器(v68)安装一个fiddler证书导入后点击关闭,会出现无响应 有时候动不动会无响应,今天百度了一下,发现真正的"罪魁祸首"是搜狗输入法,升级一下就好了 万恶的 ...
- 【Python】词典
词典 (dictionary).与列表相似,词典也可以储存多个元素.这种储存多个元素的对象称为容器(container) 基本概念 常见的创建词典的方法: >>>dic = {'to ...
- 【2018年全国多校算法寒假训练营练习比赛(第五场)-E】情人节的电灯泡(二维树状数组单点更新+区间查询)
试题链接:https://www.nowcoder.com/acm/contest/77/E 题目描述 情人节到了,小芳和小明手牵手,打算过一个完美的情人节,但是小刚偏偏也来了,当了一个明晃晃的电灯泡 ...
- Siemens
Sr.EE-Complete the electronics and mechanical designs from design concepts to mass production for RU ...