ACM ICPC

每个队伍必须是3个人

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
using namespace std;
int cmp(const void * x, const void * y) {
//x < y
return (*((double *)(x))) > (*((double *)(y))) ? : -;
}
int a[];
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
for (int i = ; i < ; i++) scanf("%d", &a[i]);
int sum = ;
for (int i = ; i < ; i++) sum += a[i];
bool f = false;
for (int i = ; i < ; i++) {
for (int j = ; j < ; j++) {
for (int k = ; k < ; k++) {
if (i != j && j != k && i != k && (a[i] + a[j] + a[k]) * == sum)f = true;
}
}
}
if (f) printf("Yes\n");
else printf("No\n");
return ;
}

Vlad and Cafes

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
using namespace std;
int cmp(const void * x, const void * y) {
//x < y
return (*((double *)(x))) > (*((double *)(y))) ? : -;
}
int a[];
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
int n, x, ans;
scanf("%d", &n);
memset(a, -, sizeof(a));
for (int i = ; i < n; i++) {
scanf("%d", &x);
a[x] = i;
ans = x;
}
for (int i = ; i < ; i++) {
if (a[i] != - && a[i] < a[ans]) ans = i;
}
printf("%d\n", ans);
return ;
}

Petya and Catacombs

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

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
using namespace std;
int cmp(const void * x, const void * y) {
//x < y
return (*((double *)(x))) > (*((double *)(y))) ? : -;
}
int a[];
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
int ans = ;
a[] = ;
int n, x;
scanf("%d", &n);
for (int i = ; i <= n; i++) {
scanf("%d", &x);
if (a[x] > ) {
a[x]--;
a[i]++;
} else {
ans++;
a[i]++;
}
}
printf("%d\n", ans);
return ;
}

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;不能存在环。

按字典序输出所有路径

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
using std::vector;
using std::sort;
int cmp(const void * x, const void * y) {
//x < y
return (*((double *)(x))) > (*((double *)(y))) ? : -;
}
bool v[], g[];
int next[], pre[];
char str[];
bool dfs(int x) {
if (g[x]) return false;
g[x] = true;
if (next[x] == ) return true;
return dfs(next[x]);
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
int n, len;
while (scanf("%d", &n) != EOF) {
memset(next, , sizeof(next));
memset(pre, , sizeof(pre));
memset(v, false, sizeof(v));
bool flag = true;
for (int i = ; i < n; i++) {
scanf("%s", str);
len = strlen(str);
for (int j = ; j < len - ; j++) {
v[str[j]] = true;
if (next[str[j]] == ) next[str[j]] = str[j + ];
else if (next[str[j]] != str[j + ]) flag = false;
if (pre[str[j + ]] == ) pre[str[j + ]] = str[j];
else if (pre[str[j + ]] != str[j]) flag = false;
}
v[str[len - ]] = true;
}
for (int i = 'a'; i <= 'z'; i++) {
memset(g, false, sizeof(g));
if (!dfs(i)) flag = false;
}
if (!flag) printf("NO\n");
else {
len = ;
for (int i = 'a'; i <= 'z'; i++) {
if (v[i]) {
bool root = true;
for (int j = 'a'; j <= 'z'; j++) if (next[j] == i) root = false;
if (!root) continue;
int ptr = i;
while (ptr != ) {
str[len++] = ptr;
v[ptr] = false;
ptr = next[ptr];
}
}
}
str[len] = '\0';
printf("%s\n", str);
}
}
return ;
}

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

题意无法理解

最新文章

  1. SubSonic3.0 Demo1.0——应用了T4模版可减少开发过程中70%以上的代码量以及80%以上的出错率
  2. CSS考试题目
  3. 04_Java面向对象特征之继承与多态
  4. [MSSQL] Useful SQL Scripts - CalendarBase
  5. linux下ping的C语言实现(转)
  6. .NET单例模式-------各种写法&amp;&amp;验证
  7. Debian 7 安装 Emacs 24.4
  8. kettle 表输入+流查询 与 数据库查询
  9. prefixfree.js介绍
  10. 银联SDK
  11. iOS第三方开源库的吐槽和备忘(转)
  12. Java提高学习之Object(5)
  13. django安装配置及测试
  14. offsetWidth, offsetHeight, offsetLeft, offsetTop,clientWidth, clientHeight,clientX,pageX,screenX
  15. 201521123011 《Java程序设计》第1周学习总结
  16. Python模块 - re
  17. Javascript的console[&#39;&#39;]几种常用输入方法
  18. Oracle中row_number()、rank()、dense_rank() 的区别
  19. Chapter3_操作符_别名机制
  20. lis nlogn算法

热门文章

  1. day001 Python 计算机基础(2019年5月16日)
  2. html 报告页面样式
  3. [系统资源]/proc/meminfo和free输出解释
  4. swift-导航栏添加自定义返回按钮
  5. 计蒜客 奇异家庭 (DP)
  6. pause、jobs、setitimer(2)、system v ipc(day12)
  7. 爬虫系列(十) 用requests和xpath爬取豆瓣电影
  8. 【Codeforces Round #519 by Botan Investments A】 Elections
  9. 解决ubuntu下wordpress设置固定链接后文章无法打开
  10. I - Tunnel Warfare