D. Decrease (Contestant ver.)

大意: 每次操作选一个最大数$-n$,其余数全$+1$. 要求构造一个序列$a$, 使得恰好$k$次操作后最大值不超过$n-1$.

只要让$k$次操作以后恰好变全为$n-1$即可.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(_i,_a,_n) for(int _i=_a;_i<=_n;++_i)
#define PER(_i,_a,_n) for(int _i=_n;_i>=_a;--_i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(_a) ({REP(_i,1,n) cout<<_a[_i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=%P;for (a%=P;n;a=a*a%P,n>>=)if(n&)r=r*a%P;return r;}
ll inv(ll x){return x<=?:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=;char p=getchar();while(p<''||p>'')p=getchar();while(p>=''&&p<='')x=x*+p-'',p=getchar();return x;}
//head ll a[]; int main() {
ll k;
cin>>k;
ll p = k/, r = k-*p;
int n = ;
REP(i,,n) a[i] = p+;
REP(i,,r) a[i]+=n-r+;
REP(i,r+,n) a[i]-=r;
printf("%d\n",n);
REP(i,,n) printf("%lld ",a[i]);hr;
}

E. Decrease (Judge ver.)

大意: 给定序列$a$, 求进行多少次$D$题中的操作后, 最大值不超过$n-1$.

暴力模拟

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(_i,_a,_n) for(int _i=_a;_i<=_n;++_i)
#define PER(_i,_a,_n) for(int _i=_n;_i>=_a;--_i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(_a) ({REP(_i,1,n) cout<<_a[_i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=%P;for (a%=P;n;a=a*a%P,n>>=)if(n&)r=r*a%P;return r;}
ll inv(ll x){return x<=?:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=;char p=getchar();while(p<''||p>'')p=getchar();while(p>=''&&p<='')x=x*+p-'',p=getchar();return x;}
//head #ifdef __APPLE__
const int N = 1e2+;
#else
const int N = 1e6+;
#endif int n;
ll a[N]; int calc() {
int ans = ;
while () {
sort(a+,a++n);
if (a[n]<=n-) break;
++ans;
a[n]-=n;
REP(i,,n-) ++a[i];
}
return ans;
} int main() {
scanf("%d", &n);
REP(i,,n) scanf("%lld",a+i);
ll ans = ;
while () {
sort(a+,a++n);
if (a[]>) {
ll t = a[]-;
ans += t*n;
REP(i,,n) a[i]-=t;
}
if (a[n]<=) {
ans += calc();
break;
}
ll ma = -;
int p = ;
REP(i,,n) if (a[i]-a[i-]>ma) ma = a[i]-a[i-], p = i;
if (ma<=) throw;
ll w = n-p+, t = (a[p]-a[p-])/(n+);
ans += t*w;
REP(i,,p-) a[i] += t*w;
REP(i,p,n) a[i] += t*(-n+w-);
}
printf("%lld\n", ans);
}

arc079的更多相关文章

  1. 【AtCoder】ARC079

    ARC079题解 C - Cat Snuke and a Voyage #include <bits/stdc++.h> #define fi first #define se secon ...

  2. Atcoder arc079 D Decrease (Contestant ver.) (逆推)

    D - Decrease (Contestant ver.) Time limit : 2sec / Memory limit : 256MB Score : 600 points Problem S ...

  3. AtCoder整理(持续更新中……)

    做了那么久的atcoder觉得自己的题解发的很乱 给有想和我一起交流atcoder题目(或者指出我做法的很菜)(或者指责我为什么整场比赛只会抄题解)的同学一个索引的机会??? 于是写了个爬虫爬了下 A ...

随机推荐

  1. CF241E Flights 题解

    题目 做了一下这道题,突然发现自己忘了差分约束,赶紧复习一下. 设当前有n个变量 a1,a2,...,an ,有若干组限制形如 ai≤aj+k (其中k为常数),则由点j向点i连一条边权为k的边,再从 ...

  2. libvirt原理

    引用原文: https://blog.csdn.net/BtB5e6Nsu1g511Eg5XEg/article/details/80142155 libvirt是目前使用最为广泛的针对KVM虚拟机进 ...

  3. for循环的嵌套之小星星。

    for循环中如何打印出五行五列的小星星呢? 很明显行列的形式需要用到循环嵌套. 外循环控制行: var str = "" ; for(var  i= 1; i <= 5; i ...

  4. javascript优先级注意点

    javascript 优先级 注意一下 && 和 == 号之间的优先级关系 请首先看如下代码, 判断下 && 和 == 的优先级 const emptyObj = {n ...

  5. [已解决] Python logging 重复打印日志信息

    问题描述 问题代码如下: def get_logger(logger_name): """得到日志对象""" logger = loggin ...

  6. 远程桌面无法连接 提示不支持FIPS安全级别的解决方法

    远程桌面可以通过网络连接到另一台电脑进行操作,可以方便在家操作公司电脑.但是到了这个新公司却出现了一个问题,提示客户端无法建立跟远程计算机的连接,我的天,要命了. 远程桌面无法连接错误提示 仔细一看说 ...

  7. iptables 端口转发--内网实现上网

    iptables -t nat -I POSTROUTING -s 192.168.0.0/24 -j SNAT --to-source 118.x.x.xiptables -A FORWARD -s ...

  8. DELPHI开始支持LINUX DOCKER

    DELPHI开始支持LINUX DOCKER 本方翻译自Marco Cantu的文章. 在过去的几年中,将服务器端解决方案(实际上是任何类型的应用程序)部署到轻量级容器而不是物理机器或虚拟机已经变得越 ...

  9. tig

    /******************************************************************************* * tig * 说明: * tig便于 ...

  10. ANR日志分析

    2018年06月27日 16:28:13 Hello__code 阅读数 3427更多 分类专栏: bug记录   版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出 ...