ACM ICPC

每个队伍必须是3个人

  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4. #include<vector>
  5. #include<algorithm>
  6. using namespace std;
  7. int cmp(const void * x, const void * y) {
  8. //x < y
  9. return (*((double *)(x))) > (*((double *)(y))) ? : -;
  10. }
  11. int a[];
  12. int main() {
  13. #ifndef ONLINE_JUDGE
  14. freopen("input.txt", "r", stdin);
  15. #endif
  16. for (int i = ; i < ; i++) scanf("%d", &a[i]);
  17. int sum = ;
  18. for (int i = ; i < ; i++) sum += a[i];
  19. bool f = false;
  20. for (int i = ; i < ; i++) {
  21. for (int j = ; j < ; j++) {
  22. for (int k = ; k < ; k++) {
  23. if (i != j && j != k && i != k && (a[i] + a[j] + a[k]) * == sum)f = true;
  24. }
  25. }
  26. }
  27. if (f) printf("Yes\n");
  28. else printf("No\n");
  29. return ;
  30. }

Vlad and Cafes

  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4. #include<vector>
  5. #include<algorithm>
  6. using namespace std;
  7. int cmp(const void * x, const void * y) {
  8. //x < y
  9. return (*((double *)(x))) > (*((double *)(y))) ? : -;
  10. }
  11. int a[];
  12. int main() {
  13. #ifndef ONLINE_JUDGE
  14. freopen("input.txt", "r", stdin);
  15. #endif
  16. int n, x, ans;
  17. scanf("%d", &n);
  18. memset(a, -, sizeof(a));
  19. for (int i = ; i < n; i++) {
  20. scanf("%d", &x);
  21. a[x] = i;
  22. ans = x;
  23. }
  24. for (int i = ; i < ; i++) {
  25. if (a[i] != - && a[i] < a[ans]) ans = i;
  26. }
  27. printf("%d\n", ans);
  28. return ;
  29. }

Petya and Catacombs

记录之前每个房间的最近访问时间,对每一个数字如果能用之前的房间来凑就先凑,凑不了就增加一个新房间。

  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4. #include<vector>
  5. #include<algorithm>
  6. using namespace std;
  7. int cmp(const void * x, const void * y) {
  8. //x < y
  9. return (*((double *)(x))) > (*((double *)(y))) ? : -;
  10. }
  11. int a[];
  12. int main() {
  13. #ifndef ONLINE_JUDGE
  14. freopen("input.txt", "r", stdin);
  15. #endif
  16. int ans = ;
  17. a[] = ;
  18. int n, x;
  19. scanf("%d", &n);
  20. for (int i = ; i <= n; i++) {
  21. scanf("%d", &x);
  22. if (a[x] > ) {
  23. a[x]--;
  24. a[i]++;
  25. } else {
  26. ans++;
  27. a[i]++;
  28. }
  29. }
  30. printf("%d\n", ans);
  31. return ;
  32. }

Restoration of string

  • If some string is the most frequent then all its substrings are the most frequent too.
  • If string ab or similar is the most frequent then letter a is always followed by letter b and b always follow a.
  • Let's consider directed graph on letters where edge a → b exists only if ab is the most frequent. If there is cycle in such graph then good string doesn't exist.
  • So such graph can be represented as several non-intersecting paths. All strings which correspond to paths must occur in non-empty good string. So if we print them in lexicographical order then we will get the answer.

有3个判定条件:每个点入度不超过1;每个点出度不超过1;不能存在环。

按字典序输出所有路径

  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4. #include<vector>
  5. #include<algorithm>
  6. using std::vector;
  7. using std::sort;
  8. int cmp(const void * x, const void * y) {
  9. //x < y
  10. return (*((double *)(x))) > (*((double *)(y))) ? : -;
  11. }
  12. bool v[], g[];
  13. int next[], pre[];
  14. char str[];
  15. bool dfs(int x) {
  16. if (g[x]) return false;
  17. g[x] = true;
  18. if (next[x] == ) return true;
  19. return dfs(next[x]);
  20. }
  21. int main() {
  22. #ifndef ONLINE_JUDGE
  23. freopen("input.txt", "r", stdin);
  24. #endif
  25. int n, len;
  26. while (scanf("%d", &n) != EOF) {
  27. memset(next, , sizeof(next));
  28. memset(pre, , sizeof(pre));
  29. memset(v, false, sizeof(v));
  30. bool flag = true;
  31. for (int i = ; i < n; i++) {
  32. scanf("%s", str);
  33. len = strlen(str);
  34. for (int j = ; j < len - ; j++) {
  35. v[str[j]] = true;
  36. if (next[str[j]] == ) next[str[j]] = str[j + ];
  37. else if (next[str[j]] != str[j + ]) flag = false;
  38. if (pre[str[j + ]] == ) pre[str[j + ]] = str[j];
  39. else if (pre[str[j + ]] != str[j]) flag = false;
  40. }
  41. v[str[len - ]] = true;
  42. }
  43. for (int i = 'a'; i <= 'z'; i++) {
  44. memset(g, false, sizeof(g));
  45. if (!dfs(i)) flag = false;
  46. }
  47. if (!flag) printf("NO\n");
  48. else {
  49. len = ;
  50. for (int i = 'a'; i <= 'z'; i++) {
  51. if (v[i]) {
  52. bool root = true;
  53. for (int j = 'a'; j <= 'z'; j++) if (next[j] == i) root = false;
  54. if (!root) continue;
  55. int ptr = i;
  56. while (ptr != ) {
  57. str[len++] = ptr;
  58. v[ptr] = false;
  59. ptr = next[ptr];
  60. }
  61. }
  62. }
  63. str[len] = '\0';
  64. printf("%s\n", str);
  65. }
  66. }
  67. return ;
  68. }

Maximum Element

You asked to find the number of permutations p of length n such that exists index i, such that pi ≠ npi is greater than any pj for j in [1, i - 1] and greater then any pj for j in [i + 1, i + k]. We will call such permutations good.

Define D(n) as number of good permutations that have pn = n. Notice that if k ≥ n, then D(n) = 0. Let w be a permutations such that wn = n. If index of element n - 1 is lesser than n - k, then w is good. Otherwise if n - 1 index is j, j ≥ n - k, then because there are less then k elements between n - 1 and nw could be good only if i from the definition would be lesser than j. In that case permutation w1, ..., wj would form a good permutation of length j of some numbers with wj being the maximum.

Therefore the following equation is correct:

Which can be computed in O(n2), or in O(n) rewritten in the form

and using prefix sums for values .

The answer is than calculated as follows:

Complexity: O(n).

Solution

Symmetric Projections

原点到点p的投影点的长度可以表示为p的横纵坐标的线性组合,所以,如果点集对某一条直线投影后关于某个点中心对称,那么这个点是点集质心对这条直线的投影。

首先求出点集的质心,对于落在质心上的一个点或关于质心对称的一对点不影响结果,可以去掉。

若此时点集中点的数量为0,则有无数条直线满足题意。

否则,对于点集中第一个点P0,枚举投影后与其对称的点,最多n个,并验证相应直线是否符合题意。

Solution(这个代码可能会由于long long数据范围问题被cha,不过数据太弱,还是a了,就没再改了)

Mod Mod Mod

题意无法理解

Codeforces Round #445的更多相关文章

  1. Codeforces Round #445 Div. 1 C Maximum Element (dp + 组合数学)

    题目链接: http://codeforces.com/contest/889/problem/C 题意: 给你 \(n\)和 \(k\). 让你找一种全排列长度为\(n\)的 \(p\),满足存在下 ...

  2. Codeforces Round #445 Div. 1

    A:每次看是否有能走回去的房间,显然最多只会存在一个,如果有走过去即可,否则开辟新房间并记录访问时间. #include<iostream> #include<cstdio> ...

  3. Codeforces Round #445 D. Restoration of string【字符串】

    D. Restoration of string time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  4. Codeforces Round #445 C. Petya and Catacombs【思维/题意】

    C. Petya and Catacombs time limit per test 1 second memory limit per test 256 megabytes input standa ...

  5. Codeforces Round #445 B. Vlad and Cafes【时间轴】

    B. Vlad and Cafes time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  6. Codeforces Round #445 A. ACM ICPC【暴力】

    A. ACM ICPC time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

  7. 【Codeforces Round #445 (Div. 2) D】Restoration of string

    [链接] 我是链接,点我呀:) [题意] 给你n个字符串. 让你构造一个字符串s. 使得这n个字符串. 每个字符串都是s的子串. 且都是出现次数最多的子串. 要求s的长度最短,且s的字典序最小. [题 ...

  8. 【Codeforces Round #445 (Div. 2) C】 Petya and Catacombs

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 看看时间戳为i的点有哪些. 每次优先用已经访问过的点. 如果不行就新创一个点. 注意新创点的时间戳也是i. [代码] #includ ...

  9. 【Codeforces Round #445 (Div. 2) B】Vlad and Cafes

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 傻逼模拟 [代码] #include <bits/stdc++.h> using namespace std; cons ...

随机推荐

  1. 浏览器内置的base64方法

    Base64是一种基于64个可打印字符来表示二进制数据的表示方法.在Base64中的可打印字符包括字母A-Z.a-z.数字0-9,这样共有62个字符,此外两个可打印符号在不同的系统中而不同(维基百科: ...

  2. java操作Excel的poi的字体设置

    package com.java.poi; import org.apache.poi.hssf.usermodel.HSSFWorkbook;import org.apache.poi.ss.use ...

  3. [转载]windows下github 出现Permission denied (publickey).解决方法

      今天在学习github的时候遇到了一些问题,然后爬了一会,找到了解决方法记录下来,以防忘记,当然能帮助别人最好啦! github教科书传送门:http://www.liaoxuefeng.com/ ...

  4. python 生成HTmL报告页面 V1.2

    上代码 # -*- coding=utf-8 -*- import time,os #数据部分 func_dict={"funcname":"模块1",} fu ...

  5. 计蒜客 奇异家庭 (DP)

    链接 : Here! 思路 : 首先这棵家族树非常非常非常有特点, 家族里的人要么没有孩子, 要么有两个孩子, 所以这棵家族树是一颗满二叉树. 设定状态 $dp[i][j]$ 为 $i$ 个人组成的不 ...

  6. [APIO2018]铁人两项 [圆方树模板]

    把这个图缩成圆方树,把方点的权值设成-1,圆点的权值设成点双的size,算 经过这个点的路径的数量*这个点的点权 的和即是答案. #include <iostream> #include ...

  7. while(Thread.activeCount() > 1)

    今天看到深入理解JVM第367页多线程volatile部分照着书本敲着代码发现了一个问题 Thread.activeCount()会一直大于2 public class VolatileTest { ...

  8. Centos 修改主机名称

    Centos 配置主机名称: 1.首先查询一下当前的主机名称 [root@localhost~]# hostnamectl status Static hostname: ****** //永久主机名 ...

  9. 35.multi-index和multi-type搜索模式

        一.multi-index和multi-type搜索模式 /_search:所有索引,所有type下的所有数据都搜索出来 /index1/_search:指定一个index,搜索其下所有typ ...

  10. Python列表、集合与字典(3)

    目录 一.列表 二.集合 三.字典 一.列表 1. 列表初识   列表的使用为处理特定顺序排列的数据提供了便利,列表元素可以是字母.数字或者其他信息,同时所加元素之间不存在任何关系.   在Pytho ...