diverta 2019 Programming Contest 2

A - Ball Distribution

特判一下一个人的,否则是\(N - (K - 1) - 1\)

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define ba 47
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N,K;
void Solve() {
read(N);read(K);
if(K == 1) puts("0");
else {
out((N - (K - 1)) - 1);enter;
}
}
int main(){
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

B - Picking Up

枚举p,q(就是枚举一个点对计算p和q),判哪一种情况最优即可

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define ba 47
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N;
map<pii,int> zz;
pii poi[55];
void Solve() {
read(N);
int x,y;
for(int i = 1 ; i <= N ; ++i) {
read(poi[i].fi);read(poi[i].se);
zz[poi[i]] = 1;
}
int ans = N;
for(int i = 1 ; i <= N ; ++i) {
for(int j = 1 ; j <= N ; ++j) {
if(i == j) continue;
int p = poi[i].fi - poi[j].fi,q = poi[i].se - poi[j].se;
int tmp = N;
for(int h = 1 ; h <= N ; ++h) {
tmp -= zz[mp(poi[h].fi - p,poi[h].se - q)];
}
ans = min(ans,tmp);
}
}
out(ans);enter; }
int main(){
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

C - Successive Subtraction

又有负数又有正数

先挑出一个正数一个负数,用这个负数减遍所有正数(除了挑出来的),再用这个正数减遍所有负数(包括挑出来的)

就可以获得所有数的绝对值和

只有正数

会牺牲一个最小的正数,方法是挑出最小的正数,再挑一个正数,用最小的正数减遍所有的正数(除了挑出来的),再用挑的正数减掉最小的正数当前的值

只有负数

会牺牲一个最小的负数,用这个负数减遍其余负数即可

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define ba 47
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N,a[100005],cnt[2];
vector<pii > ans;
int64 res = 0;
void Solve() {
read(N); for(int i = 1 ; i <= N ; ++i) {
read(a[i]);
if(a[i] < 0) cnt[0]++;
else cnt[1]++;
}
if(cnt[0] && cnt[1]) {
int s,t;
for(int i = 1 ; i <= N ; ++i) res += abs(a[i]);
for(int i = 1 ; i <= N ; ++i) {
if(a[i] >= 0) s = i;
if(a[i] < 0) t = i;
}
for(int i = 1 ; i <= N ; ++i) {
if(a[i] >= 0 && i != s) {
ans.pb(mp(a[t],a[i]));
a[t] -= a[i];
}
}
for(int i = 1 ; i <= N ; ++i) {
if(a[i] < 0) {
ans.pb(mp(a[s],a[i]));
a[s] -= a[i];
}
}
}
else if(cnt[0]) {
int p = 1;
for(int i = 2 ; i <= N ; ++i) {
if(a[i] > a[p]) p = i;
}
res += a[p];
for(int i = 1 ; i <= N ; ++i) {
if(i != p) res += abs(a[i]);
}
for(int i = 1 ; i <= N ; ++i) {
if(i != p) {
ans.pb(mp(a[p],a[i]));
a[p] -= a[i];
}
}
}
else {
int p = 1,q;
for(int i = 2 ; i <= N ; ++i) {
if(a[i] < a[p]) p = i;
}
res -= a[p];
for(int i = 1 ; i <= N ; ++i) {
if(i != p) res += a[i];
}
if(p == 1) q = 2;
else q = 1;
for(int i = 1 ; i <= N ; ++i) {
if(i != p && i != q) {
ans.pb(mp(a[p],a[i]));
a[p] -= a[i];
}
}
ans.pb(mp(a[q],a[p]));
}
out(res);enter;
for(auto t : ans) {
out(t.fi);space;out(t.se);enter;
}
}
int main(){
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

D - Squirrel Merchant

设\(f[i]\)表示有\(i\)个松果最多可以换成几个,用金银铜做背包就好了

不过这个背包大小最多可以是2500000……

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define ba 47
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int64 f[25000005],N;
int g[5][5];
void Solve() {
read(N);
for(int i = 0 ; i < 2 ; ++i) {
for(int j = 0 ; j < 3 ; ++j) {
read(g[i][j]);
}
}
for(int i = 1 ; i <= N ; ++i) f[i] = i;
for(int i = 0 ; i < 3 ; ++i) {
for(int s = g[0][i] ; s <= N ; ++s) {
f[s] = max(f[s],f[s - g[0][i]] + g[1][i]);
}
}
int all = f[N];
for(int i = 1 ; i <= all ; ++i) f[i] = i;
for(int i = 0 ; i < 3 ; ++i) {
for(int s = g[1][i] ; s <= all ; ++s) {
f[s] = max(f[s],f[s - g[1][i]] + g[0][i]);
}
}
out(f[all]);enter;
}
int main(){
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

E - Balanced Piles

计数水平不行……

这个就是,从\(0,N\)表示最大值是0,有\(N\)个数

并且我们认为相同的值选择顺序被我们确定了

如果\(D = 1\)

那么从\(x,y\),转移\(x + 1,0\)的时候,系数为1

从\(x,y\)转移到\(x,y + 1\)的时候,系数为\(y + 1\),因为我们要计数这个特定的选择顺序,在\(y\)个数的排列里插上一个数,要乘上\(y + 1\)

显然我们开头的部分需要一个\(N!\),但是由于\(H\)的\(N!\)不必要但是被算了,所以需要\(\frac{1}{N!}\),那么两个抵消了,所以可以直接这样计数

我们把转移画成一张图,发现每层转移到下一层的方案数是

\((1! + 2! +3!+4!....N!)\)

然后有\(H\)层,那么方案数是(第一层的方案是1)

\((1! + 2!+3!+4!+5!....N!)^{H - 1}N!\)

那么回到原来的问题,如果我们最大值交替一共过了\(K\)个,那么方案数是

\((1! + 2!+3!+4!+5!....N!)^{K - 1}N!\)

所以我们只要做一个路径计数,每走一步乘一个\(1! + 2!+3!+4!+5!....N!\),最后乘上一个\(\frac{N}{1!+2!+3!+4!...N!}\)

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define ba 47
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
const int MOD = 1000000007;
int N,H,D;
int fac[1000005],dp[1000006],sum[1000006];
int inc(int a,int b) {
return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
return 1LL * a * b % MOD;
}
void update(int &x,int y) {
x = inc(x,y);
}
int fpow(int x,int c) {
int res = 1,t = x;
while(c) {
if(c & 1) res = mul(res,t);
t = mul(t,t);
c >>= 1;
}
return res;
}
void Solve() {
read(N);read(H);read(D);
fac[0] = 1;
int c = 0;
for(int i = 1 ; i <= N ; ++i) {
fac[i] = mul(fac[i - 1],i);
update(c,fac[i]);
}
dp[0] = c;sum[0] = 1;
for(int i = 1 ; i <= H ; ++i) {
int t = sum[i - 1];
if(i - D > 0) update(t,MOD - sum[i - D - 1]);
dp[i] = mul(t,c);
sum[i] = inc(sum[i - 1],dp[i]);
}
int ans = mul(dp[H],fac[N]);ans = mul(ans,fpow(c,MOD - 2));
out(ans);enter;
}
int main(){
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

F - Diverta City

水平不行,想不到

还是类似数学归纳法那么构造,假如构造了\(i\)个点的完全图使得所有哈密顿路径不同,我们找到哈密顿路径最大的那个是\(M\)

然后选择一个数列

1,2,4,7,12,20,29,38,53,73

设\(M\)为i个点中最长哈密顿路径最大的那个

新加一个点\(i +1\)的时候向\(j\)连一条长度为\((M + 1)a_{j}\)的边

这个数列任意两个数相加的值不同,且不等于其中任意一个数

这样每条路径经过了两条或一条这样的边,剩余的部分的边权不足以使得两个不同的\((M + 1)k\)相等

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define ba 47
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
} int N,tot;
int64 w[15][15],M,a[] = {0,1,2,4,7,12,20,29,38,53,73};
bool vis[15];
void dfs(int dep,int pre,int64 sum) {
if(dep > tot) {
M = max(M,sum);
return;
}
for(int i = 1 ; i <= tot ; ++i) {
if(!vis[i]) {
vis[i] = 1;
dfs(dep + 1,i,sum + w[pre][i]);
vis[i] = 0;
}
}
}
void Solve() {
read(N);
M = 0;
for(int i = 2 ; i <= N ; ++i) {
for(int j = 1 ; j < i ; ++j) {
w[i][j] = w[j][i] = (M + 1) * a[j];
}
tot = i;
dfs(1,0,0);
}
for(int i = 1 ; i <= N ; ++i) {
for(int j = 1 ; j <= N ; ++j) {
out(w[i][j]);space;
}
enter;
}
}
int main(){
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

【AtCoder】diverta 2019 Programming Contest 2的更多相关文章

  1. 【AtCoder】diverta 2019 Programming Contest

    diverta 2019 Programming Contest 因为评测机的缘故--它unrated了.. A - Consecutive Integers #include <bits/st ...

  2. AtCoder diverta 2019 Programming Contest 2

    AtCoder diverta 2019 Programming Contest 2 看起来我也不知道是一个啥比赛. 然后就写写题解QWQ. A - Ball Distribution 有\(n\)个 ...

  3. 【AtCoder】ExaWizards 2019

    ExaWizards 2019 C - Snuke the Wizard 发现符文的相对位置不变,直接二分某个位置是否到达最左或最右来计算 #include <bits/stdc++.h> ...

  4. diverta 2019 Programming Contest 2自闭记

    A 签到(a-b problem不用贴了吧,以后atcoder小于300分题均不贴代码) B 发现选择的p,q一定是其中两点间的距离,于是可以O(n2)枚举两点,再O(n2)判断,其实可以做到O(n3 ...

  5. diverta 2019 Programming Contest 2

    A:签到. #include<bits/stdc++.h> using namespace std; #define ll long long #define inf 1000000010 ...

  6. diverta 2019 Programming Contest

    A:签到. #include<bits/stdc++.h> using namespace std; #define ll long long #define inf 1000000010 ...

  7. 【题解】CF1056F Write the Contest(三分+贪心+DP)

    [题解]CF1056F Write the Contest(三分+贪心+DP) 最优化问题的三个解决方法都套在一个题里了,真牛逼 最优解应该是怎样的,一定存在一种最优解是先完成了耗时长的任务再干别的( ...

  8. 【AtCoder】M-SOLUTIONS Programming Contest

    M-SOLUTIONS Programming Contest A - Sum of Interior Angles #include <bits/stdc++.h> #define fi ...

  9. 【AtCoder】ARC092 D - Two Sequences

    [题目]AtCoder Regular Contest 092 D - Two Sequences [题意]给定n个数的数组A和数组B,求所有A[i]+B[j]的异或和(1<=i,j<=n ...

随机推荐

  1. Qt 的插件制作

    首先会遇到一些插件使用的问题: 插件加载的时候出现乱码 qrc:/main.qml:20: Error: Qt.createQmlObject(): failed to create object: ...

  2. 2018-2019-2 20165234 《网络对抗技术》 Exp9 Web安全基础

    Exp9 Web安全基础 一. 实践内容 1. 安装JDK.Webgoat 2. SQL注入攻击 数字型注入(Numeric SQL Injection) 日志欺骗(Log Spoofing) 字符串 ...

  3. Ubuntu 16.04安装完重启后黑屏,光标一直闪

    原文:https://blog.csdn.net/weixin_38533896/article/details/81023690 版权声明:本文为博主原创文章,转载请附上博文链接! 安装教程网址:h ...

  4. presto计算日期间隔天数或者小时间隔——date_diff函数使用

    “Presto是Facebook最新研发的数据查询引擎,可对250PB以上的数据进行快速地交互式分析.据称该引擎的性能是 Hive 的 10 倍以上.”,亲身用过之后,觉得比hive快了10倍不止. ...

  5. chrome dev

    chrome://plugins 为什么无法打开? Chrome插件问答 2018-03-02 13:34     最后又很多网友在我们 chrome插件 网反应说chrome://plugins 无 ...

  6. 使用docker运行mysql

    以前开发的时候都是用本地的sqlite开发,但是极少数情况下,sqlite支持的语法发布到服务器上链接mysql会报错. 为了避免这种现象,还是链接本地mysql开发还是更稳定的, 可是开发的项目多了 ...

  7. PHP无限级树形结构算法(递归和引用)

    测试数组 $array = [ [, , 'name' => '这是主类'], [, , 'name' => '这是主类'], [, , 'name' => '父级为1子类'], [ ...

  8. lvs,nginx,haproxy的优缺点,适合场景

    Nginx/LVS/HAProxy的基于Linux的开源免费的负载均衡软件. LVS:使用集群技术和Linux操作系统实现一个高性能.高可用的服务器,它具有很好的可伸缩性.可靠性和可管理性,是一款强大 ...

  9. osgGA::KeySwitchMatrixManipulator 跟随

    #ifdef _WIN32 #include <Windows.h> #endif // _WIN32 #include <osg/Group> #include <os ...

  10. jvm 指令重排

    引言:在Java中看似顺序的代码在JVM中,可能会出现编译器或者CPU对这些操作指令进行了重新排序:在特定情况下,指令重排将会给我们的程序带来不确定的结果..... 1.  什么是指令重排? 在计算机 ...