Codeforces Round #708 (Div. 2) ABC1C2题解
A. Meximization
第i位优先放等于i-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 endl '\n'
#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];
int vis[maxn];
int main()
{
int kase;
cin>>kase;
while(kase--)
{
ll n = read();
rep(i,1,n) a[i] = read(), vis[i] = 0;
sort(a+1,a+1+n);
int idx = 0;
rep(i,1,n)
{
int flag = 0;
rep(j,1,n) if(!vis[j]&&a[j]==i-1)
{
flag = 1;
cout<<a[j]<<' ';
vis[j] = 1;
break;
}
if(!flag) break;
}
rep(i,1,n) if(!vis[i]) cout<<a[i]<<' ';
cout<<endl;
}
return 0;
}
B. M-arrays
将a[i]存成模m后余数的形式,那么以每个a[i]与m-a[i]匹配的方式最优。特判一下a[i]为0和a[i]==m-a[i]的情况即可。
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 endl '\n'
#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];
int main()
{
int kase;
cin>>kase;
while(kase--)
{
ll n = read(), m = read();
rep(i,1,n) a[i] = read(), a[i] %= m;
map<ll,ll> Map;
map<ll,ll> vis;
rep(i,1,n) Map[a[i]]++;
ll ans = 0;
rep(i,1,n)
{
if(vis[a[i]]) continue;
if(a[i]==0) ans += 1;
else
{
if(a[i]==m-a[i])
{
ans += 1;
}
else
{
ll mi = min(Map[a[i]], Map[m-a[i]]);
ll ma = max(Map[a[i]], Map[m-a[i]]);
ans += 1;
ans += max(ma-mi-1,0);
}
}
vis[a[i]] = 1;
vis[m-a[i]] = 1;
}
cout<<ans<<endl;
}
return 0;
}
k-LCM (hard version)
两个版本解法大同小异。先看C1,k=3时策略如下:
如果n为奇数,那么用a = (n-1)/2, b = a, c = 1即可。
若n为偶数,
且n/2是奇数,那么a = n/2, b = a, c = 2
否则直接 a = n/2, b = n/4, c = b即可。
那么C2的话,就先输出k-3个1,剩下的3个k来处理n-(k-3)又可以直接套C1方法了。
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 endl '\n'
#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} };
int main()
{
int kase;
cin>>kase;
while(kase--)
{
ll n = read(), k = read();
rep(i,4,k) cout<<1<<' ';
n -= (k-3);
ll a = 0, b = 0, c = 0;
if(n&1)
{
a = n/2;
b = a;
c = 1;
}
else
{
if((n/2)&1)
{
a = n/2 - 1;
b = a;
c = 2;
}
else
{
a = n/2;
c = a/2;
b = c;
}
}
cout<<a<<' '<<b<<' '<<c<<endl;
}
return 0;
}
Codeforces Round #708 (Div. 2) ABC1C2题解的更多相关文章
- # Codeforces Round #529(Div.3)个人题解
Codeforces Round #529(Div.3)个人题解 前言: 闲来无事补了前天的cf,想着最近刷题有点点怠惰,就直接一场cf一场cf的刷算了,以后的题解也都会以每场的形式写出来 A. Re ...
- Codeforces Round #557 (Div. 1) 简要题解
Codeforces Round #557 (Div. 1) 简要题解 codeforces A. Hide and Seek 枚举起始位置\(a\),如果\(a\)未在序列中出现,则对答案有\(2\ ...
- Codeforces Round #540 (Div. 3) 部分题解
Codeforces Round #540 (Div. 3) 题目链接:https://codeforces.com/contest/1118 题目太多啦,解释题意都花很多时间...还有事情要做,就选 ...
- Codeforces Round #538 (Div. 2) (A-E题解)
Codeforces Round #538 (Div. 2) 题目链接:https://codeforces.com/contest/1114 A. Got Any Grapes? 题意: 有三个人, ...
- Codeforces Round #531 (Div. 3) ABCDEF题解
Codeforces Round #531 (Div. 3) 题目总链接:https://codeforces.com/contest/1102 A. Integer Sequence Dividin ...
- Codeforces Round #527 (Div. 3) ABCDEF题解
Codeforces Round #527 (Div. 3) 题解 题目总链接:https://codeforces.com/contest/1092 A. Uniform String 题意: 输入 ...
- Codeforces Round #499 (Div. 1)部分题解(B,C,D)
Codeforces Round #499 (Div. 1) 这场本来想和同学一起打\(\rm virtual\ contest\)的,结果有事耽搁了,之后又陆陆续续写了些,就综合起来发一篇题解. B ...
- Codeforces Round #545 (Div. 1) 简要题解
这里没有翻译 Codeforces Round #545 (Div. 1) T1 对于每行每列分别离散化,求出大于这个位置的数字的个数即可. # include <bits/stdc++.h&g ...
- Codeforces Round #624 (Div. 3)(题解)
Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和 ...
- Codeforces Round #821(Div.2) (A-C) 题解
Codeforces Round #821(Div.2) (A-C) A.Consecutive Sum 大致题意 给定一组共 n 个数据 ,如果俩个数的下标在 mod k 意义下同余,则可以交换a[ ...
随机推荐
- ApplicationContext 接口的实现类
ClassPathXmlApplicationContext: 它是从类的根路径下加载配置文件 推荐使用这种 FileSystemXmlApplicationContext: 它是从磁盘路径上加载配置 ...
- 从零实现富文本编辑器#2-基于MVC模式的编辑器架构设计
在先前的规划中我们是需要实现MVC架构的编辑器,将应用程序分为控制器.模型.视图三个核心组件,通过控制器执行命令时会修改当前的数据模型,进而表现到视图的渲染上.简单来说就是构建一个描述文档结构与内容的 ...
- Argo CD
目录 一.什么是 Argo CD 二.为什么选择 Argo CD 三.Argo CD 架构 1.API服务器 2.存储库服务器 3.应用程序控制器 四.Argo CD 的使用 1.要求 2.安装 Ar ...
- Python提交 post方法之‘Content-Type‘: multipart/form-datay
最近写s2_061 Python脚本得时候遇到了POST 提交 'Content-Type': multipart/form-data 这个问题,然后查阅资料开始解决. 一.首先说一下POST 提交数 ...
- 基于Python和uiautomation的Windows桌面自动化操作方案
基于Python和uiautomation的Windows桌面自动化操作方案 在日常开发和测试过程中,我们经常需要对Windows桌面应用程序进行自动化操作.本文将记录如何使用uiautomation ...
- 工具 | webshell-decryptor
0x00 简介 webshell-decryptor是一款通过获取到的webshell流量.url.key来还原攻击者使用webshell所做操作的工具. 下载地址: webshell-decrypt ...
- 彻底掌握 PCA 降维
PCA 这类的降维算法, 我算是接触好几年了有, 从我学营销的时候, 市场研究方面就经常会用到,相关的还有 "因子分析" 比如, 商品形象认知, 客户细分等场景. 其实多年前我就能 ...
- 操作系统:虚拟机内核--KVM是什么
随着云计算.大数据和分布式技术的演进,我们需要在一台服务器上虚拟化出更多虚拟机,还要让这些虚拟机能够弹性伸缩,实现跨主机的迁移. 而虚拟化技术正是这些能力的基石. 亚马逊.阿里.腾讯等知名公司用到的云 ...
- C#之可访问性约束(可访问性不一致)
C# 语言中的有些构造要求某个类型至少与某个成员或其他类型具有同样的可访问性 (at least as accessible as).如果 T 的可访问域是 M 可访问域的超集,我们就说类型 T 至少 ...
- 部署Spring Boot项目详细教程
首先Spring Boot项目能正常使用IP地址搭配接口在浏览器正常运行 第一步: 打开Maven里面Lifecycle下面的package或者是install双击运行(需要有网络) 第二步: 查看运 ...