A. Ahahahahahahahaha

题意:给个一个偶数长度的01序列,要求删除不超过2/n个元素使得奇数位和等于偶数位和。

思路:注意到题目给的提示,只有0和1,且为偶数长度。

那么对和有贡献的也就只有1,而且0或1总有一个出现次数小于等于n/2。

所以我们就有这样的策略,把最后搞的只剩0或者1即可,0的个数小就删0,反之删1。

最后注意只保留1的时候还要考虑一下答案数组长度的奇偶性。

view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} }; ll a[maxn];
ll n; int main()
{
int kase;
cin>>kase;
while(kase--)
{
vector<ll> ans;
n = read();
rep(i,1,n) a[i] = read();
ll sum = 0;
rep(i,1,n) sum += a[i];
if(sum > n/2)
{
rep(i,1,n) if(a[i]==1) ans.pb(a[i]);
if(ans.size()&1)
{
ans.pop_back();
}
}
else rep(i,1,n) if(a[i]==0) ans.pb(a[i]);
if(ans.size()==1) ans[0] = 0;
cout<<ans.size()<<'\n';
for(int i=0; i<ans.size(); i++) cout<<ans[i]<<' ';
cout<<'\n';
}
return 0;
}

B. Big Vova

题意:给一个a数组,问你构造一个b序列,使得存在c序列,其中c[i] = gcd(b[1],b[2],...,b[i]),且c的字典序最大。

思路:贪心,第一个肯定是最大的那个元素。然后每次暴力枚举出下一位能放的产生gcd最大的那个即可。

view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} }; ll n;
ll a[maxn];
ll vis[1005]; int main()
{
int kase;
cin>>kase;
while(kase--)
{
vector<ll> ans;
mem(vis,0);
ll n = read();
rep(i,1,n) a[i] = read();
sort(a+1,a+1+n);
ll m = a[n];
ans.pb(m);
ll cnt = 1;
while(cnt<n)
{
ll ma = 0, pos = 0;
per(i,n-1,1) if(!vis[i]&&gcd(a[i],m)>ma||(!vis[i]&&gcd(a[i],m)==ma&&a[pos]>a[i])) ma = gcd(a[i],m), pos = i;
cnt++;
ans.pb(a[pos]);
m = ma;
vis[pos] = 1;
}
rep(i,1,n) cout<<ans[i-1]<<' ';
cout<<'\n';
}
return 0;
}

C. Chocolate Bunny

题意:交互题,有一个n排列(没告诉你长什么样),你每次可以问它p[i]%p[j]的结果,然后他会告诉你这个值。让你在不超过2n的询问下把这个序列求出来。

思路:第一次做交互题刚开始有点蒙圈

其实想到一个点就可以立马A掉了。我们用双指针从头尾两端开始遍历。每次询问两个,(p,q)和(q,p),因为肯定要么是a[p] > a[q] 要么是a[q] > a[p],所以结果肯定一个等于两者之间的最小值,一个是比这个最小值要小。所以我们每两次询问都能得到一个a[p]或a[q],然后移动指针即可。如2%5 和 5%2 ,分别是2和1,所以a[p]肯定是2。

具体详见代码。

view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} }; ll a[maxn];
ll vis[maxn]; int main()
{
ll n = read();
int p = 1, q = n;
int cnt = 0;
while(cnt<=n-1&&p<q)
{
printf("? %d %d\n", p, q);
fflush(stdout);
ll r1 = read();
printf("? %d %d\n", q, p);
fflush(stdout);
ll r2 = read();
if(r1 > r2) a[p] = r1, p++,vis[r1]=1;
else a[q] = r2, q--, vis[r2]=1;
cnt++;
}
ll sum = (1+n)*n/2;
ll all = 0;
rep(i,1,n) all += a[i];
rep(i,1,n) if(a[i]==0) a[i] = sum - all;
printf("! ");
rep(i,1,n) printf("%lld%c",a[i], i==n?'\n':' ');
fflush(stdout);
return 0;
}

Codeforces Round #669 ABC 题解的更多相关文章

  1. Codeforces Round #543 Div1题解(并不全)

    Codeforces Round #543 Div1题解 Codeforces A. Diana and Liana 给定一个长度为\(m\)的序列,你可以从中删去不超过\(m-n*k\)个元素,剩下 ...

  2. Codeforces Round #545 Div1 题解

    Codeforces Round #545 Div1 题解 来写题解啦QwQ 本来想上红的,结果没做出D.... A. Skyscrapers CF1137A 题意 给定一个\(n*m\)的网格,每个 ...

  3. Codeforces Round #539 Div1 题解

    Codeforces Round #539 Div1 题解 听说这场很适合上分QwQ 然而太晚了QaQ A. Sasha and a Bit of Relax 翻译 有一个长度为\(n\)的数组,问有 ...

  4. Educational Codeforces Round 64 部分题解

    Educational Codeforces Round 64 部分题解 不更了不更了 CF1156D 0-1-Tree 有一棵树,边权都是0或1.定义点对\(x,y(x\neq y)\)合法当且仅当 ...

  5. Educational Codeforces Round 64部分题解

    Educational Codeforces Round 64部分题解 A 题目大意:给定三角形(高等于低的等腰),正方形,圆,在满足其高,边长,半径最大(保证在上一个图形的内部)的前提下. 判断交点 ...

  6. Codeforces Round div2 #541 题解

    codeforces Round #541 abstract: I构造题可能代码简单证明很难 II拓扑排序 III并查集 启发式排序,带链表 IV dp 处理字符串递推问题 V 数据结构巧用:于二叉树 ...

  7. [Codeforces Round #461 (Div2)] 题解

    [比赛链接] http://codeforces.com/contest/922 [题解] Problem A. Cloning Toys          [算法] 当y = 0 ,   不可以 当 ...

  8. Educational Codeforces Round 63部分题解

    Educational Codeforces Round 63 A 题目大意就不写了. 挺简单的,若果字符本来就单调不降,那么就不需要修改 否则找到第一次下降的位置和前面的换就好了. #include ...

  9. Codeforces Round #669 (Div. 2)A-C题解

    A. Ahahahahahahahaha 题目:http://codeforces.com/contest/1407/problem/A 题解:最多进行n/2的操作次数,我们统计这n个数中1的个数,是 ...

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

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

随机推荐

  1. java 限流

    题记 在高并发的分布式系统中,我们都需要考虑接口并发量突增时造成的严重后果,后端服务的高压力严重甚至会导致系统宕机.为避免这种问题,我们都会为接口添加限流.降级.熔断等能力,从而使接口更为健壮. 限流 ...

  2. python,批量修改文件后缀名

    比如,D盘test目录下有以下几个没有后缀的文件,需要修改为txt结尾 python代码如下 # python批量更换后缀名 import os import sys #需要修改后缀的文件目录 os. ...

  3. 【自用】restful api 常用状态码

    GET(SELECT):从服务器取出资源(一项或多项). POST(CREATE):在服务器新建一个资源. PUT(UPDATE):在服务器更新资源(客户端提供改变后的完整资源). PATCH(UPD ...

  4. 康谋分享 | aiSim5 物理相机传感器模型验证方法(一)

    摘要: aiSim5可以实时模拟复杂的传感器配置,在多GPU分布式渲支持的支持下,aiSim可以渲染20多个摄像头.10多个雷达和10多个激光雷达在同一环境下运行.aiSim5独有的实时渲染引擎能够满 ...

  5. MySQL 中 AUTO_INCREMENT 列达到最大值时会发生什么?

    在MySQL中,AUTO_INCREMENT列用于自动生成唯一的数字值,通常用于主键.当AUTO_INCREMENT列达到最大值时,会发生以下几种情况,具体取决于列的数据类型以及MySQL的配置. 对 ...

  6. K8s容器运行时,移除Dockershim后存在哪些疑惑?

    K8s容器运行时,移除Dockershim后存在哪些疑惑? 大家好,我是秋意零. K8s版本截止目前(24/09)已经发布到了1.31.x版本.早在K8s版本从1.24.x起(22/05),默认的容器 ...

  7. PC端自动化测试实战教程-3-pywinauto 启动PC端应用程序 - 下篇(详细教程)

    1.简介 经过上一篇的学习.介绍和了解,pywinauto的强大,不言而喻吧!宏哥讲解和分享的是电脑自带和安装的应用程序.有些小伙伴或者童鞋们已经迫不及待地私信宏哥,如果在电脑中这个应用程序已经启用了 ...

  8. 使用了下UOS浏览器,突然不想说话了

    使用了UOS20,安装上了,但是要激活:我蒙了!好吧,适用下吧: 看下浏览器情况: UOS浏览器 5.1.2365.0 (正式版本) stable (64 位) 修订版本 3cfecd947e7bc5 ...

  9. 鸿蒙 NEXT (一)初识鸿蒙

    @charset "UTF-8"; .markdown-body { line-height: 1.75; font-weight: 400; font-size: 15px; o ...

  10. TVM图级优化了解

    TVM图级优化按照优化范围,可分为局部优化和全局优化 局部优化是TVM图级优化的重点,其中算子融合是AI编译器必不可少的优化方法. 算子融合核心思想就是将多个算子合并成一个内核,因而无需将中间结果写回 ...