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: 但与一 ...
随机推荐
- Mysql 基本用法
Java中两种常用的数据库: MYSQL Oracle MYSQL :开源免费的数据库,小型的数据库.由瑞典MySQL AB 公司开发,适合中小企业使用,由C语言和C++编写的.已经被Ora ...
- Spring Boot 快速入门(IDEA)
从字面理解,Boot是引导的意思,因此SpringBoot帮助开发者快速搭建Spring框架:SpringBoot帮助开发者快速启动一个Web容器:SpringBoot继承了原有Spring框架的优秀 ...
- jdbc例子
public class ConnMysql { public static void main(String[] args) throws ClassNotFoundException, SQLEx ...
- Vue初步认识
什么是Vue Vue (读音 /vjuː/,类似于 view) 是一套用于构建用户界面的渐进式框架(根据需求使用特定的功 能).与其它大型框架不同的是,Vue 被设计为可以自底向上逐层应用.Vue 的 ...
- apue.3e源码下载及编译
下载地址:http://www.apuebook.com/code3e.html 编译方法:http://blog.sina.com.cn/s/blog_94977c890102vdms.html
- Java多线程 - 线程组
Java使用ThreadGroup来表示线程组,用以对一批线程进行分类管理. Java允许程序对线程组直接进行控制,对线程组的控制相当于同时控制这批线程: 用户创建的所有线程都属于指定线程组,如果程序 ...
- thinkphp <eq> <if>标签 condition中可以写PHP的判断逻辑
<ul> <volist name="monthArray" id="monthItem"> <if condition=&quo ...
- spring mvc:复选框(多选)
以user为例,user下有 username用户,password密码, address地址, receivePaper是否订阅, favotireFramework兴趣爱好, user.java ...
- Ajax-07 基于Ajax实现跨域请求
跨域 跨域名访问,如c1.com域名向c2.com域名发送请求 本质:浏览器存在同源策略机制,同源策略阻止从一个源加载的文档或脚本获取或设置另一个源加载的文档的属性. django服务端准备 url. ...
- Forms and Reports Developer 10g Certified on Windows 10 for EBS 12.x
Forms Developer 10g and Reports Developer 10g are now certified on Windows 10 desktops for E-Busines ...