Codeforces Round #669 (Div. 2)A-C题解
A. Ahahahahahahahaha
题目:http://codeforces.com/contest/1407/problem/A
题解:最多进行n/2的操作次数,我们统计这n个数中1的个数,是否过半,如果没有代表0过半,因此输出剩余的0的个数即可
如果1的个数过半,则考虑1的个数是奇数还是偶数,若为奇数,则再减去一个输出;若为偶数个,则直接输出。
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; int main()
{
int t,n,i,j;
cin>>t;
while(t--)
{
cin>>n;
int num=;
for(i=;i<=n;i++)
{
int x;
cin>>x;
if(x==)
num++;
}
if(num<=n/)
{
cout<<n/<<endl;
for(int j=;j<=n/;j++)
cout<<""<<" ";
cout<<endl;
}
else
{
if(num%==)
{
cout<<num<<endl;
for(int j=;j<=num;j++)
cout<<""<<" ";
cout<<endl;
}
else
{
cout<<num-<<endl;
for(int j=;j<=num-;j++)
cout<<""<<" ";
cout<<endl;
}
}
}
return ;
}
B. Big Vova
题目:http://codeforces.com/contest/1407/problem/B
题解:首先挑选出最大的作为第一个,将其与第一个数互换位置,然后开始从第二位一直到第n位,遍历求出当前最大的gcd,并记录相应的下标,然后和第二到第n位交换位置,最多执行n-1次。
最后输出数组即可。
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; int t,n,a[];
int gcd(int a,int b)
{
return b==?a:gcd(b,a%b);
} int main()
{
int i,j,maxn;
cin>>t;
while(t--)
{
cin>>n;
int f;
int maxn=-;
for(i=;i<n;i++)
{
cin>>a[i];
if(a[i]>maxn)
{
maxn=a[i];
f=i;
}
}
swap(a[f],a[]);
int cnt=;
while(cnt<n)
{
int maxgcd=-;
int p;
for(i=cnt;i<n;i++)
{
if(gcd(maxn,a[i])>maxgcd)
{
maxgcd=gcd(maxn,a[i]);
p=i;
}
}
swap(a[cnt],a[p]);
maxn=maxgcd;
cnt++;
}
for(i=;i<n;i++)
cout<<a[i]<<" ";
cout<<endl;
}
return ;
}
C. Chocolate Bunny
题目:http://codeforces.com/contest/1407/problem/C
题解:这是一道交互题,以前没碰到过,也好理解。
可以询问 2×n2×n 次,每次给出两个不同的索引 i 和 j,会返回 ai%aj的值。
询问i和j,假设ai>aj,那结果为ai%aj=x<aj
再询问j和i,结果为aj%ai=y=aj
因此aj=y;并将y这个值用map标记,mp[y]=1
反之,若ai<aj,询问i和j,结果为ai%aj=x=ai
再询问j和i,结果为aj%ai=y<ai
因此ai=x,并将x用map标记,mp[x]=1;
最后遍历完整个数组后,还剩下一个,遍历数组找到mp还未标记的那个数,即为最终的a[f]的值
最后输出数组即可。
代码:
#include<bits/stdc++.h>
using namespace std; const int N=;
int x,y,n;
int a[N];
map<int,int>mp;
int main()
{
int i,j;
cin>>n;
int f=;
for(i=;i<=n;i++)
{
cout<<"? "<<f<<" "<<i<<endl;
cin>>x;
cout<<"? "<<i<<" "<<f<<endl;
cin>>y;
if(x>y)
{
a[f]=x;
mp[x]=;
f=i;
}
else
{
a[i]=y;
mp[y]=;
}
}
for(i=;i<=n;i++)
{
if(mp[i]==)
continue;
a[f]=i;
break;
}
cout<<"!";
for(i=;i<=n;i++)
cout<<" "<<a[i];
return ;
}
Codeforces Round #669 (Div. 2)A-C题解的更多相关文章
- Codeforces Round #612 (Div. 2) 前四题题解
这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...
- Codeforces Round #198 (Div. 2)A,B题解
Codeforces Round #198 (Div. 2) 昨天看到奋斗群的群赛,好奇的去做了一下, 大概花了3个小时Ak,我大概可以退役了吧 那下面来稍微总结一下 A. The Wall Iahu ...
- Codeforces Round #672 (Div. 2) A - C1题解
[Codeforces Round #672 (Div. 2) A - C1 ] 题目链接# A. Cubes Sorting 思路: " If Wheatley needs more th ...
- Codeforces Round #669 (Div. 2) C. Chocolate Bunny 题解(交互)
题目链接 题目大意 有一个长度为n的全排列,你可以询问2n次,要你经过这个2n次的询问后,求出这个全排列 询问定义为:输入"? i j"输出\(p_{i} mod p_{j}\) ...
- Codeforces Round #614 (Div. 2) A-E简要题解
链接:https://codeforces.com/contest/1293 A. ConneR and the A.R.C. Markland-N 题意:略 思路:上下枚举1000次扫一遍,比较一下 ...
- Codeforces Round #610 (Div. 2) A-E简要题解
contest链接: https://codeforces.com/contest/1282 A. Temporarily unavailable 题意: 给一个区间L,R通有网络,有个点x,在x+r ...
- Codeforces Round #611 (Div. 3) A-F简要题解
contest链接:https://codeforces.com/contest/1283 A. Minutes Before the New Year 题意:给一个当前时间,输出离第二天差多少分钟 ...
- Codeforces Round #499 (Div. 2) D. Rocket题解
题目: http://codeforces.com/contest/1011/problem/D This is an interactive problem. Natasha is going to ...
- Codeforces Round #499 (Div. 2) C Fly题解
题目 http://codeforces.com/contest/1011/problem/C Natasha is going to fly on a rocket to Mars and retu ...
随机推荐
- “随手记”开发记录day10
今天完成了各个demo合并,并进行测试,中间出现了一些bug, 例如再点击主页面预留的菜单按钮时会出现闪退 在手机上运行更新页面时会直接崩溃 还有发现的问题有,不能查看往期的记录
- 用python分析1225万条淘宝数据,终于搞清楚了我的交易行为
大家好,我是黄同学
- windows 下部署 .netcore 到 docker
前面我们演示了如何将 Asp.Net Core 程序部署到 iis 和 部署到 windows 服务.其实前面的都是铺垫,如何将 Asp.Net Core 站点部署到 docker 才是这个系列文章的 ...
- akka-typed(9) - 业务分片、整合,谈谈lagom, 需要吗?
在讨论lagom之前,先从遇到的需求开始介绍:现代企业的it系统变得越来越多元化.复杂化了.线上.线下各种系统必须用某种方式集成在一起.从各种it系统的基本共性分析:最明显的特征应该是后台数据库的角色 ...
- ALGEBRA-1 向量空间
向量空间对加法封闭 对数乘封闭 直和:表示的唯一性
- 浏览器编年史与UserAgent大乱斗
1993 世界上第一个支持显示图片的浏览器Mosaic诞生 为了区分浏览器是否能显示图片,UserAgent诞生了,Mosaic将自己标志为NCSA_Mosaic/2.0(windows 3.1) 1 ...
- C#设计模式之7-桥接模式
桥接模式(Bridge Pattern) 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/401 访问. 桥接模式属于结构 ...
- Oracle数据库启动及状态等查询
一.监听 1)启动监听: lsnrctl start 2)查看监听状态: lsnrctl status 3)停止监听: lsnrctl stop 4)检查是否可进行网络连接: tnsping ${si ...
- 【有向图】强连通分量-Tarjan算法
好久没写博客了(都怪作业太多,绝对不是我玩的太嗨了) 所以今天要写的是一个高大上的东西:强连通 首先,是一些强连通相关的定义 //来自度娘 1.强连通图(Strongly Connected Grap ...
- adb命令将抓包工具证书从用户目录移动至系统目录,解决反爬对于本地证书认证
代码和注释 adb shell #连接手机进入shell模式 #su root #如果你不root权限可以试着这个一般都是root cd /data/misc/user/0/cacerts-added ...