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题解的更多相关文章

  1. Codeforces Round #612 (Div. 2) 前四题题解

    这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...

  2. Codeforces Round #198 (Div. 2)A,B题解

    Codeforces Round #198 (Div. 2) 昨天看到奋斗群的群赛,好奇的去做了一下, 大概花了3个小时Ak,我大概可以退役了吧 那下面来稍微总结一下 A. The Wall Iahu ...

  3. Codeforces Round #672 (Div. 2) A - C1题解

    [Codeforces Round #672 (Div. 2) A - C1 ] 题目链接# A. Cubes Sorting 思路: " If Wheatley needs more th ...

  4. Codeforces Round #669 (Div. 2) C. Chocolate Bunny 题解(交互)

    题目链接 题目大意 有一个长度为n的全排列,你可以询问2n次,要你经过这个2n次的询问后,求出这个全排列 询问定义为:输入"? i j"输出\(p_{i} mod p_{j}\) ...

  5. Codeforces Round #614 (Div. 2) A-E简要题解

    链接:https://codeforces.com/contest/1293 A. ConneR and the A.R.C. Markland-N 题意:略 思路:上下枚举1000次扫一遍,比较一下 ...

  6. Codeforces Round #610 (Div. 2) A-E简要题解

    contest链接: https://codeforces.com/contest/1282 A. Temporarily unavailable 题意: 给一个区间L,R通有网络,有个点x,在x+r ...

  7. Codeforces Round #611 (Div. 3) A-F简要题解

    contest链接:https://codeforces.com/contest/1283 A. Minutes Before the New Year 题意:给一个当前时间,输出离第二天差多少分钟 ...

  8. Codeforces Round #499 (Div. 2) D. Rocket题解

    题目: http://codeforces.com/contest/1011/problem/D This is an interactive problem. Natasha is going to ...

  9. 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 ...

随机推荐

  1. Python基础教程,流程控制语句详解

    1.程序结构 计算机在解决问题时,分别是顺序执行所有语句.选择执行部分语句.循环执行部分语句,分别是:顺序结构.选择结构.循环结构.如下图: 很多人学习python,不知道从何学起.很多人学习pyth ...

  2. Vouch-proxy 实现 Zabbix4.4 对接 SSO

    Vouch-proxy 实现 Zabbix 对接 SSO Zabbix 自身不支持 SSO 对接,我使用 Nginx 代理 Zabbix,将请求转发至 Vouch-proxy,由 Vouch-prox ...

  3. MacOS下如何优雅的使用冰蝎

    因为冰蝎也是使用 JAVA 写的跨平台应用程序,我们可以借助 macOS 自带的 自动操作 automator.app 来创建一个应用程序. 前言: 冰蝎是一种新型的Webshell连接工具,在日常的 ...

  4. Vue Element-UI 中列表单选的实现

    el-table中单选的实现 引用场景: 选择单条数据进行业务操作 实现方式: 给el-table-column设置el-radio Template 代码 <div class="r ...

  5. python基本数据类型(二)

    列表   list 1.list.append( p_object) ----  增加列表参数(向后追加) list=['lifei','liuhua','laochai'] list.append( ...

  6. Vue学习(十三)模版引擎算是预处理器吗?

    前言 今天在看vue-loader预处理器配置相关的内容,突然看到了Pug,然后有了一个疑问:模版引擎原来是预处理器吗? 答案是:YES 说明 这里重点讨论使用不同的js模板引擎作为预处理器, 下面示 ...

  7. windows下RocketMQ的安装部署

    一.预备环境 1.系统 Windows 2. 环境 JDK1.8.Maven.Git 二. RocketMQ部署 1.下载 1.1地址:http://rocketmq.apache.org/relea ...

  8. RSA非对称加密(java实例代码)

    使用RSA对WebService传递的信息加密解密的基本思想是:服务器端提供一个WebService方法String getServerPublicKey(),客户端可以以此得到服务器端的公钥,然后使 ...

  9. SEGGER studio问题

    刚开始学习用SEGGER studio编译调试nordic 52840程序,在此记录遇到的问题. 1.  Additional Load File[0]:"E:\nordic/nRF5_SD ...

  10. zookeeper简单实现注册与发现以及其他基本操作

    添加依赖 <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookee ...