Codeforces Round #445
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 ≠ n, pi 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 n, w 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).
Symmetric Projections
原点到点p的投影点的长度可以表示为p的横纵坐标的线性组合,所以,如果点集对某一条直线投影后关于某个点中心对称,那么这个点是点集质心对这条直线的投影。
首先求出点集的质心,对于落在质心上的一个点或关于质心对称的一对点不影响结果,可以去掉。
若此时点集中点的数量为0,则有无数条直线满足题意。
否则,对于点集中第一个点P0,枚举投影后与其对称的点,最多n个,并验证相应直线是否符合题意。
Solution(这个代码可能会由于long long数据范围问题被cha,不过数据太弱,还是a了,就没再改了)
Mod Mod Mod
题意无法理解
Codeforces Round #445的更多相关文章
- Codeforces Round #445 Div. 1 C Maximum Element (dp + 组合数学)
题目链接: http://codeforces.com/contest/889/problem/C 题意: 给你 \(n\)和 \(k\). 让你找一种全排列长度为\(n\)的 \(p\),满足存在下 ...
- Codeforces Round #445 Div. 1
A:每次看是否有能走回去的房间,显然最多只会存在一个,如果有走过去即可,否则开辟新房间并记录访问时间. #include<iostream> #include<cstdio> ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 【Codeforces Round #445 (Div. 2) D】Restoration of string
[链接] 我是链接,点我呀:) [题意] 给你n个字符串. 让你构造一个字符串s. 使得这n个字符串. 每个字符串都是s的子串. 且都是出现次数最多的子串. 要求s的长度最短,且s的字典序最小. [题 ...
- 【Codeforces Round #445 (Div. 2) C】 Petya and Catacombs
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 看看时间戳为i的点有哪些. 每次优先用已经访问过的点. 如果不行就新创一个点. 注意新创点的时间戳也是i. [代码] #includ ...
- 【Codeforces Round #445 (Div. 2) B】Vlad and Cafes
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 傻逼模拟 [代码] #include <bits/stdc++.h> using namespace std; cons ...
随机推荐
- (转)C#开发微信门户及应用(2)--微信消息的处理和应答
http://www.cnblogs.com/wuhuacong/p/3614175.html 微信应用如火如荼,很多公司都希望搭上信息快车,这个是一个商机,也是一个技术的方向,因此,有空研究下.学习 ...
- Linux 帮助与语言设置以及(\)
1.命令太长可以用反斜杠(\)来转义回车键,使用命令连续到下一行.注意:反斜杠后就立刻接着特殊字符才能转义. 2.修改语系为英文 LANG=en_US.utf8 export LC ALL=en_US ...
- 从输入url到页面展示出来经历了哪些过程
本文只是一个整理向的随笔,以个人思路来简化的同时进行适当的拓展,如有错误,欢迎指正. 1.输入网址. 此时得到一个url 2.域名解析 整个过程都是dns系统在发挥作用,它的目的是将域名和ip对应起 ...
- XML的解析方式
//解析和输出XML public void showXml() { string filepath = Application.dataPath + @"/my.xml"; if ...
- 原生js通过最外层id获取下面指定的子元素
需求:在vue中使用v-for循环出来的元素,设置动态id,之后获取下面的所有textarea标签 template: <table cellpadding = 2 v-for="(i ...
- 死磕itchat源码--config.py
itchat的配置文件,源码: import os, platform # 版本及微信的url,二维码等 VERSION = '1.3.10' BASE_URL = 'https://login.we ...
- 获取第n天日期
function datezh(s){ return s = s>9 ? s:"0"+s } function dateTime(t){ var getNowTime = v ...
- 【剑指Offer】20、包含min函数的栈
题目描述: 定义栈的数据结构,请在该类型中实现一个能够得到栈中所含最小元素的min函数(时间复杂度应为O(1)). 解题思路: 使用两个stack,一个为数据栈,另一个为辅助栈.数据栈 ...
- 洛谷P1583 魔法照片【模拟+排序】
一共有n(n≤20000)个人(以1--n编号)向佳佳要照片,而佳佳只能把照片给其中的k个人.佳佳按照与他们的关系好坏的程度给每个人赋予了一个初始权值W[i].然后将初始权值从大到小进行排序,每人就有 ...
- 爬虫写法进阶:普通函数--->函数类--->Scrapy框架
本文转载自以下网站: 从 Class 类到 Scrapy https://www.makcyun.top/web_scraping_withpython12.html 普通函数爬虫: https:// ...