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 ivorysifreopen("f1.in","r",stdin);
#endifSolve();
}

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 ivorysifreopen("f1.in","r",stdin);
#endifSolve();
}

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 ivorysifreopen("f1.in","r",stdin);
#endifSolve();
}

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 ivorysifreopen("f1.in","r",stdin);
#endifSolve();
}

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 ivorysifreopen("f1.in","r",stdin);
#endifSolve();
}

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 ivorysifreopen("f1.in","r",stdin);
#endifSolve();
}

转载于:https://www.cnblogs.com/ivorysi/p/11068533.html

【AtCoder】diverta 2019 Programming Contest 2相关推荐

  1. 【画画】UCF Local Programming Contest 2012(Practice)E. Pete's Pantry

    题目链接https://www.jisuanke.com/contest/7332 纯粹的画画题(可光题意就理解了一年) 此生再也不愿意做这种题(流泪) #include<bits/stdc++ ...

  2. 【AtCoder】ARC 081 E - Don't Be a Subsequence

    [题意]给定长度为n(<=2*10^5)的字符串,求最短的字典序最小的非子序列字符串. http://arc081.contest.atcoder.jp/tasks/arc081_c [算法]字 ...

  3. 【Atcoder】ARC083 D - Restoring Road Network

    [算法]图论,最短路? [题意]原图为无向连通图,现给定原图的最短路矩阵,求原图最小边权和,n<=300. [题解]要求最小边权和下,原图的所有边一定是所连两端点的最短路. 那么现在将所有最短路 ...

  4. 【AtCoder】ARC095 E - Symmetric Grid 模拟

    [题目]E - Symmetric Grid [题意]给定n*m的小写字母矩阵,求是否能通过若干行互换和列互换使得矩阵中心对称.n,m<=12. [算法]模拟 [题解]首先行列操作独立,如果已确 ...

  5. 【LOJ3077】「2019 集训队互测 Day 4」绝目编诗

    [题目链接] 点击打开链接 [思路要点] 不难发现各个边双连通分量可以分开处理,桥边可以直接删除. 可以证明,对于每一个边双连通分量,当 M−NM-NM−N 超过 O(N)O(\sqrt{N})O(N ...

  6. 【Atcoder】Atcoder Beginner Contest 50

    战况:VP,1.2水题,3题一开始WA了,居然没有想到用快速幂,后来看了题解会了,T4没看.目前ABC已补.缺D. T1: A - Addition and Subtraction Easy 题意:求 ...

  7. 【Atcoder】AtCoder Beginner Contest 174总结

    目录 A Air Conditioner B Distance C Repsept D Alter Altar E Logs F Range Set Query A B C D E F √ √ ● ○ ...

  8. 【AtCoder】Japanese Student Championship 2019 Qualification题解

    Japanese Student Championship 2019 Qualification题解 A. Takahashi Calendar ◇题目传送门◆ 题目大意 定义Product Day为 ...

  9. 【AtCoder】AtCoder Grand Contest 046

    比赛链接 点击打开链接 官方题解 点击打开链接 Problem A. Takahashikun, The Strider 可以发现,任意时刻,玩家均位于以前两次操作路径的中垂线的交点上. 因此,答案即 ...

最新文章

  1. 深度学习先驱Bengio:AI顶会论文的Deadline是时候取消了
  2. 巧用shell+rsync服务实现日志自动过滤处理压缩并上传日志服务器,自动分类
  3. 解决SpringBoot更新数据到MySQL乱码问题
  4. 97. Leetcode 剑指 Offer 60. n个骰子的点数 (动态规划-背包问题)
  5. 埃罗芒阿老师计算机谱,[B型]ヒトリゴト-埃罗芒阿老师OP 完整版
  6. 华为鸿蒙分布式系统2020,鸿蒙2.0来了!华为开发者大会HDC 2020宣布
  7. centos7php自启动,centos7系统下nginx安装并配置开机自启动操作
  8. Eclipse启动SpringCloud微服务集群的方法
  9. 不止是替代 看南天信息与浪潮的金融国产化实践
  10. 【ffmpeg】overlay带有透明通道的视频
  11. [应用代码] android 自动接听电话和挂断 (适合目前所有版本)
  12. 喜马拉雅音频下载工具 - xmlyfetcher
  13. html5如何直接源码,html5源码可以直接使用吗
  14. pdf文件的预览——几种方式实现——技能提升
  15. 微信公众号小程序怎么做?
  16. 在线免费caj转Word,不用安装软件
  17. java+selenium爬取图片签名
  18. 这是最好的企业管理手册
  19. EduCoder-Web程序设计基础-html5—表格高级样式的设置-第2关:设置表格的外边框样式
  20. DB2性能调整优化问题

热门文章

  1. LeetCode 04寻找两个正序数组的中位数(困难)二分法
  2. 北大OJ百练——3179:最长单词(C语言)
  3. Hibernate之Session解析
  4. android信息中字符个数,在android中指定编辑文本中的字符数
  5. 综合评价模型的缺点_视频/图像质量评价综述(一)
  6. 【实验】 策略路由配置案例
  7. linux 跟踪程序执行过程,用pvtrace和Graphviz实现对linux下C程序的函数调用跟踪
  8. 程序员修炼之路:你该知道的 7 个必经阶段
  9. 这件事,阿里爱了10年
  10. 怎样删除oracle中的用户,Oracle 中删除已经连接的用户