arc079
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的更多相关文章
- 【AtCoder】ARC079
ARC079题解 C - Cat Snuke and a Voyage #include <bits/stdc++.h> #define fi first #define se secon ...
- Atcoder arc079 D Decrease (Contestant ver.) (逆推)
D - Decrease (Contestant ver.) Time limit : 2sec / Memory limit : 256MB Score : 600 points Problem S ...
- AtCoder整理(持续更新中……)
做了那么久的atcoder觉得自己的题解发的很乱 给有想和我一起交流atcoder题目(或者指出我做法的很菜)(或者指责我为什么整场比赛只会抄题解)的同学一个索引的机会??? 于是写了个爬虫爬了下 A ...
随机推荐
- javascript优先级注意点
javascript 优先级 注意一下 && 和 == 号之间的优先级关系 请首先看如下代码, 判断下 && 和 == 的优先级 const emptyObj = {n ...
- TDD(测试驱动开发)
什么是 TDDTDD 有广义和狭义之分,常说的是狭义的 TDD,也就是 UTDD(Unit Test Driven Development).广义的 TDD 是 ATDD(Acceptance Tes ...
- java列队使用案例
java队列是一种特殊的线性表,它只允许在表的前端进行删除操作,而在表的后端进行插入操作. 具有先进先出的特性 LinkedList类实现了Queue接口,因此我们可以把LinkedList当成Que ...
- js数组reduce()方法的使用和一些应用场景
reduce()的使用 reduce()方法为归并类方法,最常见的应用场景就是,计算数组中每一项的总和. reduce()方法会遍历数组的每一项,它接收两个参数: 第一个参数是:每次遍历都会调用的函数 ...
- sentinel-dashboard安装、运行(docker)
https://github.com/alibaba/Sentinel/releases 下载源码 修改成支持nacos(略) mkdir /opt/sentinel-dashboard把编译好的se ...
- redis集群搭建及启动、停止、重启操作【转】
redis版本:redis-5.0.3.tar.gz 操作系统:完全新安装的centos7.6系统 使用一台虚拟机模拟6个redis节点,3个master,3个slave,虚拟机IP为192.168. ...
- 使用ES6删除对象中某些属性
const form = { id: '011', name: '测试一', description: '测试demo' } // 目标: 取到删除description属性的对象, 即下文的data ...
- Visionworks OpenVX
[TOC] Visionworks OpenVX OpenVX heterogeneous computation framework Spec OpenVX 1.2源碼解析 - 目錄結構 除了官方的 ...
- Laravel 控制器 Controller
一.控制器存在的意义 路由可以分发请求:路由中还可以引入 html 页面:我们可以在 route/web.php 中搞定一切了:但是如果把业务逻辑都写入到路由中:那路由将庞大的难以维护:于是控制器就有 ...
- NodeJs FS 文件系统模块
1. fs.stat 检测是文件还是目录 fs.stat('html',function(err,stats){ if(err){ console.log(err); return false; } ...