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 ...
随机推荐
- yum 安装,可以list,但是无法安装Error downloading packages: 。。。。 No such file or directory
yum 安装,可以list,但是无法安装Error downloading packages: .... No such file or directory # yum install nano Lo ...
- sourceforge文件下载过慢
sourceforge文件下载过慢,可以用下面网址镜像下载, http://sourceforge.mirrorservice.org 按搜索到的项目的英文字母依次查询,如http://sourcef ...
- UDF——计算壁面边界合力矩(旋转机械)
- Hotspot对象的内存布局
对象头 class oopDesc { ... private: volatile markOop _mark; union _metadata { Klass* _klass; narrowKlas ...
- 记一次MyBatisPlus问题(如果表名是数据库关键字怎么办)
问题信息:如果表名是数据库关键字怎么办? 正常来说,如果是我们自己写sql的话,给表名加反引号即可解决问题. 但是由于我们使用MyBatisPlus,相关的sql基本上都是封装并自动生成的.如果是这种 ...
- gitosis管理员的密钥丢失解决办法
前提:win10默认安装配置完git:已经在linux服务器上配置完gitosis. 适用于:gitosis管理员的密钥丢失的情况 解决办法分三步: 1.git bash命令行下,将新的密钥中的公钥上 ...
- sharding jdbc(sphere) 3.1.0 spring boot配置
sharding jdbc 2.x系列详解参见https://www.cnblogs.com/zhjh256/p/9221634.html. 最近将sharding jdbc的配置从xml切换到了sp ...
- i系列标准-互联网周刊
原文:http://www.enet.com.cn/article/2019/0429/A20190429062899.html 传统意义上的规模.现代意义上的工具时代感.永远不会改变的最高意义上的使 ...
- pytharm里面的导入上级目录飘红
有时候导入本地模块或者py文件时,下方会出现红色的波浪线,但不影响程序的正常运行,但是在查看源函数文件时,会出现问题 问题如下: 解决方案: 1. 进入设置,找到Console下的Python Con ...
- jmeter beanshell 从文件中获取随机参数
loadruner 参数化有个功能,可以设置在脚本每次出现参数时,自动更换参数值.在做jmeter自动化测试过程中,同一个请求中出现多个参数值,如一个接口可以添加n个信息的请求 [ { "n ...