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. GEE windows 环境配置

    参照GEE开发大神的一篇文章GEE学习笔记 三十五:windows下配置本地开发环境 - 无形的风的文章 - 知乎. 按他的顺序下来还是出了点问题,再整理一下自己遇到的问题. 1.安装Google的 ...

  2. TensorFlow 报错 ValueError: Can't load save_path when it is None.

    原因 : 模型还未生成出来 , 此时你去检测的生成完毕的模型 , 模型呢 ? 还没生成 . 模型还没生成就引用了为什么不报错 ? 解决办法 : 当前情况不要以为是你的程序有 bug , 而是你的模型还 ...

  3. java NIO面试题剖析

    转载:https://mp.weixin.qq.com/s/YIcXaH7AWLJbPjnTUwnlyQ 首先我们分别画图来看看,BIO.NIO.AIO,分别是什么? BIO:传统的网络通讯模型,就是 ...

  4. ubuntu之路——day19.1 深度CNN的探究

    1.经典的CNN LeNet-5 1998的CNN鼻祖 以前用的sigmoid和tanh 下图给的是relu和softmax AlexNet ImageNet2012的冠军 VGG-16 ImageN ...

  5. 微信小程序图片宽度100%,高度自适应

    实现图片自适应,按照一般情况只需设置: img { width: 100%; height: auto; } 但是微信小程序里是特例,需要image标签上设置属性mode=widthFix,就是hei ...

  6. str.replace替换变量名的字符串

    网易云课堂该课程链接地址 https://study.163.com/course/courseMain.htm?share=2&shareId=400000000398149&cou ...

  7. Android仿微信QQ等实现锁屏消息提醒

    demo代码如下: import android.content.Intent; import android.os.Bundle; import android.support.v7.app.App ...

  8. 使用bugly热更新时自定义升级弹窗的UI样式

    项目的热更新用的bugly,不过一直都只是使用他自带的升级弹窗. 不过UI小姐姐说弹窗太丑了,要自定义. bugly有提供自定义UI的官方文档:https://bugly.qq.com/docs/us ...

  9. python初级(302) 6 对象(三)

    一.复习 1.什么是魔法方法? 2.什么是类的初始化函数? 二.什么是self 使用一个类可以创建多个对象实例,例如: ball1 = Ball("red", "smal ...

  10. javascript Round Function

    var rounded = Math.round( number * 10 ) / 10; // round to one digit var rounded = Math.round( number ...