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);
}

最新文章

  1. LAMP_源码安装全教程
  2. LintCode 392 House Robber
  3. JS代码实用代码实例(输入框监听,点击显示点击其他地方消失,文件本地预览上传)
  4. Nagios 自定义插件与安装使用之监控dead datanodes
  5. 安卓中級教程(1):@InjectView
  6. Java创建Web项目
  7. UVA 11235 (游程编码+ST算法)
  8. linux shell 输入密码不显示
  9. 触发器 &#39;SA.U_USER_INFO_TRG&#39; 无效且未通过重新验证--Oracle序列
  10. 后台动态设置前台标签内容和属性(转自http://www.wzsky.net/html/Program/net/26171.html)
  11. 5. Android框架和工具之 ZXing(二维码)
  12. 进程间通信之管道(pipe、fifo)
  13. css3中定义required,focus,valid和invalid样式
  14. js中 的这些距离你知道吗?
  15. Linux系统手动安装rpm包依赖关系分析(以Kernel升级为例)
  16. 在 WPF 中使用 Path 路径
  17. Linux scp sudo
  18. 运用jieba库 寻找高频词
  19. java.lang.ClassNotFoundException: org.apache.storm.topology.IRichSpout
  20. centos7下 nginx配置upstream 不能直接代理到本机tomcat的解决

热门文章

  1. javaScript 迭代器
  2. linux高性能服务器编程 (五) --Linux网络编程基础api
  3. Java String.split()函数分隔回车注意事项
  4. 【Beta】Scrum meeting 8 &amp; 助教参会记录
  5. CloudFlare上线了新的Proxy Anything选项, 支持转发TCP连接
  6. 阿里云OSS设置跨域访问 H5的时候
  7. [转]怎样与 CORS 和 cookie 打交道
  8. FreeSWITCH视频直播
  9. 支付宝小程序开发——H5跳转到小程序(获取小程序页面的链接)
  10. 使用 atom 将 makedown 编辑并转换成 pdf