2018 AICCSA Programming Contest

Tree Game

Rectangles

思路:如果存在大于0的交面积的话, 那么肯定能找到一条水平的直线 和 一条垂直的直线,

使得水平直线的左右两边点的个数相等且为n, 垂直直线的左右两边点的个数相等且为n

也就是说不能有点在这两条线上, 否则交面积为0

然后左上角的点和右下角的点配对, 左下角的点和右上角的点配对

代码:

  1. #pragma GCC optimize(2)
  2. #pragma GCC optimize(3)
  3. #pragma GCC optimize(4)
  4. #include<bits/stdc++.h>
  5. using namespace std;
  6. #define fi first
  7. #define se second
  8. #define pi acos(-1.0)
  9. #define LL long long
  10. //#define mp make_pair
  11. #define pb push_back
  12. #define ls rt<<1, l, m
  13. #define rs rt<<1|1, m+1, r
  14. #define ULL unsigned LL
  15. #define pll pair<LL, LL>
  16. #define pli pair<LL, int>
  17. #define pii pair<int, int>
  18. #define piii pair<pii, int>
  19. #define mem(a, b) memset(a, b, sizeof(a))
  20. #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  21. #define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
  22. //head
  23.  
  24. const int N = 2e5 + , M = 1e5 + ;
  25. const int MOD = 1e9 + ;
  26. pii a[N];
  27. int fac[M];
  28. bool cmp(pii a, pii b) {
  29. return a.se < b.se;
  30. }
  31. void init() {
  32. fac[] = ;
  33. for (int i = ; i < M; i++) fac[i] = (1LL * fac[i-] * i) % MOD;
  34. }
  35. int main() {
  36. int T, n;
  37. init();
  38. scanf("%d", &T);
  39. while(T--) {
  40. scanf("%d", &n);
  41. for (int i = ; i <= *n; i++) scanf("%d %d", &a[i].fi, &a[i].se);
  42. bool f = false;
  43. sort(a+, a++*n);
  44. double x = , y = ;
  45. if(a[n].fi != a[n+].fi) x = (a[n].fi + a[n+].fi) / 2.0;
  46. else f = true;
  47.  
  48. sort(a+, a++*n, cmp);
  49. if(a[n].se != a[n+].se) y = (a[n].se + a[n+].se) / 2.0;
  50. else f = true;
  51. int cnt = ;
  52. for (int i = ; i <= *n; i++) if(a[i].fi > x && a[i].se > y) cnt++;
  53. if(f) printf("0\n");
  54. else printf("%lld\n", (1LL * fac[cnt] * fac[n-cnt]) % MOD);
  55. }
  56. return ;
  57. }

Function

思路:打表找规律, 发现ai的系数为C(n+1, i) - 1

代码:

  1. #pragma GCC optimize(2)
  2. #pragma GCC optimize(3)
  3. #pragma GCC optimize(4)
  4. #include<bits/stdc++.h>
  5. using namespace std;
  6. #define fi first
  7. #define se second
  8. #define pi acos(-1.0)
  9. #define LL long long
  10. //#define mp make_pair
  11. #define pb push_back
  12. #define ls rt<<1, l, m
  13. #define rs rt<<1|1, m+1, r
  14. #define ULL unsigned LL
  15. #define pll pair<LL, LL>
  16. #define pli pair<LL, int>
  17. #define pii pair<int, int>
  18. #define piii pair<pii, int>
  19. #define mem(a, b) memset(a, b, sizeof(a))
  20. #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  21. #define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
  22. //head
  23.  
  24. const int N = 1e6 + ;
  25. const int MOD = 1e9 + ;
  26. int a[N];
  27. LL fac[N], inv[N];
  28. LL q_pow(LL n, LL k) {
  29. LL ans = ;
  30. while(k) {
  31. if(k&) ans = (ans * n) % MOD;
  32. n = (n * n) % MOD;
  33. k >>= ;
  34. }
  35. return ans;
  36. }
  37. void init() {
  38. fac[] = ;
  39. for (int i = ; i < N; i++) fac[i] = fac[i-] * i % MOD;
  40. inv[N-] = q_pow(fac[N-], MOD-);
  41. for (int i = N-; i >= ; i--) inv[i] = inv[i+] * (i+) % MOD;
  42. }
  43. LL C(int n, int m) {
  44. return fac[n] * inv[m] % MOD * inv[n-m] % MOD;
  45. }
  46. int main() {
  47. int T;
  48. init();
  49. scanf("%d", &T);
  50. while(T--) {
  51. int n;
  52. scanf("%d", &n);
  53. for (int i = ; i <= n; i++) scanf("%d", &a[i]);
  54. LL ans = ;
  55. for (int i = ; i <= n; i++) {
  56. (ans = ans + (C(n+, i) - ) * a[i] % MOD) %= MOD;
  57. }
  58. printf("%lld\n", (ans + MOD) % MOD);
  59. }
  60. return ;
  61. }

Two Sequences

思路:将a数组放到集合里, 方便查找删除

代码:

  1. #pragma GCC optimize(2)
  2. #pragma GCC optimize(3)
  3. #pragma GCC optimize(4)
  4. #include<bits/stdc++.h>
  5. using namespace std;
  6. #define fi first
  7. #define se second
  8. #define pi acos(-1.0)
  9. #define LL long long
  10. //#define mp make_pair
  11. #define pb push_back
  12. #define ls rt<<1, l, m
  13. #define rs rt<<1|1, m+1, r
  14. #define ULL unsigned LL
  15. #define pll pair<LL, LL>
  16. #define pli pair<LL, int>
  17. #define pii pair<int, int>
  18. #define piii pair<pii, int>
  19. #define mem(a, b) memset(a, b, sizeof(a))
  20. #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  21. #define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
  22. //head
  23.  
  24. const int N = 1e5 + ;
  25. int a[N], b[N];
  26. multiset<int> s;
  27. vector<int> vc;
  28. int main() {
  29. int T, n, k;
  30. scanf("%d", &T);
  31. while(T--) {
  32. scanf("%d %d", &n, &k);
  33. s.clear();
  34. vc.clear();
  35. for (int i = ; i <= n; i++) scanf("%d", &a[i]), s.insert(a[i]);
  36. for (int i = ; i <= n; i++) scanf("%d", &b[i]);
  37. for (int i = ; i <= n; i++) {
  38. multiset<int>:: iterator it = s.lower_bound(b[i]);
  39. if(it == s.end() || *it != b[i]) {
  40. vc.pb(b[i]);
  41. }
  42. else s.erase(it);
  43. }
  44. if((int)vc.size() == ) puts("YES");
  45. else if((int)vc.size() == ) {
  46. if(*s.begin() - k <= vc[] && vc[] <= *s.begin() + k) puts("YES");
  47. else puts("NO");
  48. }
  49. else puts("NO");
  50. }
  51. return ;
  52. }

Connecting Components

Mirror

TeddyBearsDay

思路:对于每个点, 它连向父亲的边只有当它的子树中不能自销的多余部分才会用到

代码:

  1. #pragma GCC optimize(2)
  2. #pragma GCC optimize(3)
  3. #pragma GCC optimize(4)
  4. #include<bits/stdc++.h>
  5. using namespace std;
  6. #define fi first
  7. #define se second
  8. #define pi acos(-1.0)
  9. #define LL long long
  10. //#define mp make_pair
  11. #define pb push_back
  12. #define ls rt<<1, l, m
  13. #define rs rt<<1|1, m+1, r
  14. #define ULL unsigned LL
  15. #define pll pair<LL, LL>
  16. #define pli pair<LL, int>
  17. #define pii pair<int, int>
  18. #define piii pair<pii, int>
  19. #define mem(a, b) memset(a, b, sizeof(a))
  20. #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  21. #define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
  22. //head
  23.  
  24. const int N = 1e4 + ;
  25. vector<pii> g[N];
  26. int send[N], rev[N];
  27. LL ans = ;
  28.  
  29. pii dfs(int u, int o, int w) {
  30. pii tmp = {send[u], rev[u]};
  31. for (pii p : g[u]) {
  32. if(p.fi != o) {
  33. pii pp = dfs(p.fi, u, p.se);
  34. tmp.fi += pp.fi;
  35. tmp.se += pp.se;
  36. }
  37. }
  38. ans += 1LL * abs(tmp.fi - tmp.se) * w;
  39. return tmp;
  40. }
  41. int main() {
  42. int T, n, u, v, w, q;
  43. scanf("%d", &T);
  44. while(T--) {
  45. scanf("%d", &n);
  46. for (int i = ; i <= n; i++) g[i].clear(), send[i] = rev[i] = ;
  47. for (int i = ; i < n; i++) {
  48. scanf("%d %d %d", &u, &v, &w);
  49. g[u].pb({v, w});
  50. g[v].pb({u, w});
  51. }
  52. scanf("%d", &q);
  53. while(q--) {
  54. scanf("%d %d", &u, &v);
  55. send[u]++;
  56. rev[v]++;
  57. }
  58. ans = ;
  59. dfs(, , );
  60. printf("%lld\n", ans);
  61. }
  62. return ;
  63. }

Win Strategy

思路:背包dp变形

代码:

  1. #pragma GCC optimize(2)
  2. #pragma GCC optimize(3)
  3. #pragma GCC optimize(4)
  4. #include<bits/stdc++.h>
  5. using namespace std;
  6. #define fi first
  7. #define se second
  8. #define pi acos(-1.0)
  9. #define LL long long
  10. //#define mp make_pair
  11. #define pb push_back
  12. #define ls rt<<1, l, m
  13. #define rs rt<<1|1, m+1, r
  14. #define ULL unsigned LL
  15. #define pll pair<LL, LL>
  16. #define pli pair<LL, int>
  17. #define pii pair<int, int>
  18. #define piii pair<pii, int>
  19. #define mem(a, b) memset(a, b, sizeof(a))
  20. #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  21. #define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
  22. //head
  23.  
  24. const int N = 1e3 + ;
  25. pii a[N];
  26. int dp[N];
  27. int main() {
  28. int T, n, L;
  29. scanf("%d", &T);
  30. while(T--) {
  31. scanf("%d %d", &n, &L);
  32. for (int i = ; i <= n; i++) scanf("%d %d", &a[i].fi, &a[i].se);
  33. for (int i = ; i <= L; i++) dp[i] = ;
  34. for (int i = ; i <= n; i++) {
  35. for (int j = L; j >= a[i].se; j--) {
  36. if(j-a[i].se + >= a[i].fi) dp[j] = max(dp[j], dp[j-a[i].se] + );
  37. }
  38. }
  39. printf("%d\n", dp[L]);
  40. }
  41. return ;
  42. }

Tours

思路:二分答案, check时对于每辆bus, 如果它上一天是空闲的, 才能填补今天的空缺, 然后今天原本的车就是昨天需要的车, 不够的拿昨天剩余的补

代码:

  1. #pragma GCC optimize(2)
  2. #pragma GCC optimize(3)
  3. #pragma GCC optimize(4)
  4. #include<bits/stdc++.h>
  5. using namespace std;
  6. #define fi first
  7. #define se second
  8. #define pi acos(-1.0)
  9. #define LL long long
  10. //#define mp make_pair
  11. #define pb push_back
  12. #define ls rt<<1, l, m
  13. #define rs rt<<1|1, m+1, r
  14. #define ULL unsigned LL
  15. #define pll pair<LL, LL>
  16. #define pli pair<LL, int>
  17. #define pii pair<int, int>
  18. #define piii pair<pii, int>
  19. #define mem(a, b) memset(a, b, sizeof(a))
  20. #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  21. #define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
  22. //head
  23.  
  24. const int N = 1e5 + ;
  25. vector<int> a[N];
  26. int T, m, n, r, t, tmp[N];
  27. bool check(int x) {
  28. int pre = ;
  29. for (int i = ; i <= n; i++) {
  30. if(i == ) {
  31. int tot = ;
  32. for (int j = ; j <= m; j++) {
  33. tmp[j] = (a[j][i] + r - ) / r;
  34. tot += tmp[j];
  35. }
  36. if(tot > x) return false;
  37. pre = x - tot;
  38. }
  39. else {
  40. int tot = ;
  41. for (int j = ; j <= m; j++) {
  42. if(tmp[j] >= (a[j][i] + r - ) / r) tmp[j] = (a[j][i] + r - ) / r;
  43. else {
  44. if(pre >= (a[j][i] + r - ) / r - tmp[j]) pre -= (a[j][i] + r - ) / r - tmp[j];
  45. else return false;
  46. tmp[j] = (a[j][i] + r - ) / r;
  47. }
  48. tot += (a[j][i] + r - ) / r;
  49. }
  50. if(tot > x) return false;
  51. pre = x - tot;
  52. }
  53. }
  54. return true;
  55. }
  56. int main() {
  57. scanf("%d", &T);
  58. while(T--) {
  59. scanf("%d %d %d", &m, &n, &r);
  60. for (int i = ; i <= m; i++) {
  61. a[i].clear();
  62. a[i].pb();
  63. for (int j = ; j <= n; j++) {
  64. scanf("%d", &t);
  65. a[i].pb(t);
  66. }
  67. }
  68. int l = , r = 5e5, mid = l+r >> ;
  69. while(l < r) {
  70. if(check(mid)) r = mid;
  71. else l = mid+;
  72. mid = l+r >> ;
  73. }
  74. printf("%d\n", mid);
  75. }
  76. return ;
  77. }

Restricted Vertex Cover

思路:2-sat

建边:

对于一条mark的边,

如果其中一点在点覆盖中, 那么另外一点肯定不在点覆盖中

如果其中一点不在点覆盖中, 那么另外一点肯定在点覆盖中

对于一条unmark的边,

如果其中一点在点覆盖中, 那么另外一点不确定

如果其中一点不在点覆盖中, 那么另外一点肯定在点覆盖中

代码:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int N=;
  4. int ins[N],dfn[N],low[N],cnt,sta[N];
  5. int top,v,u;
  6. int Next[N],head[N],to[N];
  7. int tot;
  8. int scc[N];
  9. int scccnt;
  10. void make_list(int u,int v){
  11. Next[++tot]=head[u],head[u]=tot,to[tot]=v;
  12. }
  13. void tarjan(int x){
  14. ins[x]=dfn[x]=low[x]=++cnt,sta[top++]=x;
  15. for(int p=head[x],v=to[p];p;p=Next[p],v=to[p])
  16. if(!dfn[v])tarjan(v),low[x]=min(low[x],low[v]);
  17. else if(ins[v])low[x]=min(low[x],dfn[v]);
  18. if(low[x]==dfn[x]){
  19. scc[x]=++scccnt,ins[x]=;
  20. while((u=sta[--top])!=x)ins[u]=,scc[u]=scccnt;
  21. }
  22. }
  23. int main(){
  24. int T;
  25. int n,m;
  26. int u,v,w;
  27. scanf("%d",&T);
  28. for(int t=;t<=T;t++){
  29. scanf("%d%d",&n,&m);
  30. memset(head,,sizeof(int)*(n*+));
  31. memset(dfn,,sizeof(int)*(n*+));
  32. top=;
  33. tot=;
  34. memset(scc,,sizeof(int)*(n*+));
  35. memset(low,,sizeof(int)*(n*+));
  36. scccnt=;
  37. memset(ins,,sizeof(int)*(n*+));
  38. cnt=;
  39. memset(sta,,sizeof(int)*(n*+));
  40. for(int i=;i<=m;i++){
  41. scanf("%d%d%d",&u,&v,&w);
  42. if(w){
  43. make_list(u,v+n);
  44. make_list(v,u+n);
  45. make_list(u+n,v);
  46. make_list(v+n,u);
  47. }
  48. else{
  49. make_list(u+n,v);
  50. make_list(v+n,u);
  51. }
  52. }
  53. for(int i=;i<=*n;i++){
  54. if(!dfn[i])tarjan(i);
  55. }
  56. bool ok=;
  57. for(int i=;i<=n;i++){
  58. ok&=(scc[i]!=scc[i+n]);
  59. }
  60. if(ok)puts("YES");
  61. else puts("NO");
  62. }
  63. return ;
  64. }

2018 AICCSA Programming Contest的更多相关文章

  1. 2018 JUST Programming Contest 1.0 题解

    题目链接  gym101778 Problem A 转化成绝对值之后算一下概率.这个题有点像 2018 ZOJ Monthly March Problem D ? 不过那个题要难一些~ #includ ...

  2. AtCoder SoundHound Inc. Programming Contest 2018 E + Graph (soundhound2018_summer_qual_e)

    原文链接https://www.cnblogs.com/zhouzhendong/p/AtCoder-SoundHound-Inc-Programming-Contest-2018-E.html 题目 ...

  3. 2018 ACM-ICPC, Syrian Collegiate Programming Contest

    2018 ACM-ICPC, Syrian Collegiate Programming Contest A Hello SCPC 2018! 水题 B Binary Hamming 水题 C Por ...

  4. 2018 German Collegiate Programming Contest (GCPC 18)

    2018 German Collegiate Programming Contest (GCPC 18) Attack on Alpha-Zet 建树,求lca 代码: #include <al ...

  5. The 2018 ACM-ICPC China JiangSu Provincial Programming Contest快速幂取模及求逆元

    题目来源 The 2018 ACM-ICPC China JiangSu Provincial Programming Contest 35.4% 1000ms 65536K Persona5 Per ...

  6. (寒假开黑gym)2018 ACM-ICPC, Syrian Collegiate Programming Contest(爽题)

    layout: post title: (寒假开黑gym)2018 ACM-ICPC, Syrian Collegiate Programming Contest(爽题) author: " ...

  7. ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2018) Syria, Lattakia, Tishreen University, April, 30, 2018

    ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2018) Syr ...

  8. (寒假开黑gym)2018 ACM-ICPC, Syrian Collegiate Programming Contest

    layout: post title: (寒假开黑gym)2018 ACM-ICPC, Syrian Collegiate Programming Contest author: "luow ...

  9. (寒假GYM开黑)2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)

    layout: post title: 2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018) author: &qu ...

随机推荐

  1. Git本地分支和远程分支关联

    转载:https://blog.csdn.net/cherishhere/article/details/52606884 转载:https://blog.zengrong.net/post/1746 ...

  2. C++max的使用方法

    #include <iostream> //#include <algorithm>//std::min std::max #include <stdint.h> ...

  3. PyCharm笔记之首次安装和激活

    转载:http://www.cnblogs.com/Ivyli4258/p/7440147.html PyCharm是一种Python IDE,带有一整套可以帮助用户在使用Python语言开发时提高其 ...

  4. CentOS7 安装git服务器

    在CentOS7系统中安装git服务器有两种方法,分别为yum安装和下载git安装包手动安装,这篇文章只有下载git安装包手动安装方法. 方法一:使用yum安装 暂无 方法二:下载git安装包手动安装 ...

  5. UML(统一建模语言)是通用的可视化标准建模语言。由构造块、公共机制、构架三部分组成。

    UML UML(统一建模语言)是通用的可视化标准建模语言.由构造块.公共机制.构架三部分组成. 1.构造块:包括基本的UML建模元素(类.接口.用例等).关系(关联关系.依赖关系.泛化关系.实现关系) ...

  6. loj#2510. 「AHOI / HNOI2018」道路 记忆化,dp

    题目链接 https://loj.ac/problem/2510 思路 f[i][a][b]表示到i时,公路个数a,铁路个数b 记忆化 复杂度=状态数=\(nlog^2n\) 代码 #include ...

  7. 【系列教程1】Gradle入门系列三:依赖管理

    在现实生活中,要创造一个没有任何外部依赖的应用程序并非不可能,但也是极具挑战的.这也是为什么依赖管理对于每个软件项目都是至关重要的一部分. 这篇教程主要讲述如何使用Gradle管理我们项目的依赖,我们 ...

  8. nginx 配置 https 请求

    1,先去这个网站申请一下证书 https://certmall.trustauth.cn/Home/Member/index/id/1521167511.html 上面会教你怎么去做. 2,就是配置自 ...

  9. Lintcode455-StudentID-Easy

    Implement a class Class with the following attributes and methods: A public attribute students which ...

  10. 无法启动此程序,因为计算机中丢失api-ms-win-crt-runtime-|1-1-0.dll

    今天想把自己电脑上的python2换成python3时,安装完python3后,命令行启动时需要出现了上述错误,在网上查了资料后应该是库文件遭到了破坏,于是我下了一个东西安装后就解决了,如果出现了此问 ...