Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) A B C D 水 模拟 构造
2 seconds
512 megabytes
standard input
standard output
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back.
Jinotega's best friends, team Base have found a list of their itinerary receipts with information about departure and arrival airports. Now they wonder, where is Jinotega now: at home or at some competition far away? They know that:
- this list contains all Jinotega's flights in this year (in arbitrary order),
- Jinotega has only flown from his hometown to a snooker contest and back,
- after each competition Jinotega flies back home (though they may attend a competition in one place several times),
- and finally, at the beginning of the year Jinotega was at home.
Please help them to determine Jinotega's location!
In the first line of input there is a single integer n: the number of Jinotega's flights (1 ≤ n ≤ 100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next n lines there is flight information, one flight per line, in form "XXX->YYY", where "XXX" is the name of departure airport "YYY" is the name of arrival airport. Exactly one of these airports is Jinotega's home airport.
It is guaranteed that flights information is consistent with the knowledge of Jinotega's friends, which is described in the main part of the statement.
If Jinotega is now at home, print "home" (without quotes), otherwise print "contest".
4
SVO
SVO->CDG
LHR->SVO
SVO->LHR
CDG->SVO
home
3
SVO
SVO->HKT
HKT->SVO
SVO->RAP
contest
In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list.
题意:给你n张机票 包含机票的起点与终点 判断当前是否在家或在外
题解:水
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <map>
#define ll __int64
using namespace std;
int n;
char a[];
char b[],c[];
int main()
{
scanf("%d",&n);
getchar();
scanf("%s",a);
int ans=;
for(int i=;i<=n;i++)
{
scanf("%s->%s",c);
b[]=c[];
b[]=c[];
b[]=c[];
if(strcmp(a,b)==)
{
ans++;
}
}
if(n%!=||ans!=(n/))
{
printf("contest\n");
}
else
printf("home\n");
return ;
}
2 seconds
512 megabytes
standard input
standard output
Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming contest.
To obfuscate the code, Kostya first looks at the first variable name used in his program and replaces all its occurrences with a single symbol a, then he looks at the second variable name that has not been replaced yet, and replaces all its occurrences with b, and so on. Kostya is well-mannered, so he doesn't use any one-letter names before obfuscation. Moreover, there are at most 26 unique identifiers in his programs.
You are given a list of identifiers of some program with removed spaces and line breaks. Check if this program can be a result of Kostya's obfuscation.
In the only line of input there is a string S of lowercase English letters (1 ≤ |S| ≤ 500) — the identifiers of a program with removed whitespace characters.
If this program can be a result of Kostya's obfuscation, print "YES" (without quotes), otherwise print "NO".
abacaba
YES
jinotega
NO
In the first sample case, one possible list of identifiers would be "number string number character number string number". Here how Kostya would obfuscate the program:
- replace all occurences of number with a, the result would be "a string a character a string a",
- replace all occurences of string with b, the result would be "a b a character a b a",
- replace all occurences of character with c, the result would be "a b a c a b a",
- all identifiers have been replaced, thus the obfuscation is finished.
题意:规定了一种字符串的处理方式 对于遇到的第一个字符用‘a’替换之后出现的相同字符 之后找到下一个未被替换的字符 替换为‘b’ 规则同上
题解:给你一段处理过的字符串 判断是否合法. 直接模拟即可。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <map>
#define ll __int64
using namespace std;
char a[];
map<char,int> mp;
int main()
{
scanf("%s",a);
int len=strlen(a);
char be='a';
mp.clear();
for(int i=;i<len;i++)
{
if(mp[a[i]]==)
continue;
if(a[i]==be)
{
be++;
}
else
{
printf("NO\n");
return ;
}
for(int j=i;j<len;j++)
{
if(a[i]==a[j])
{
mp[a[i]]=;
}
}
}
printf("YES\n");
return ;
}
2 seconds
512 megabytes
standard input
standard output
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly k points, the score is reset and a new set begins.
Across all the sets Misha scored a points in total, and Vanya scored b points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible.
Note that the game consisted of several complete sets.
The first line contains three space-separated integers k, a and b (1 ≤ k ≤ 109, 0 ≤ a, b ≤ 109, a + b > 0).
If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.
11 11 5
1
11 2 3
-1
Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem.
题意:两人打乒乓球比赛 双方中只要有一人得k分则本局结束 给你a b分别为两人的总得分 问 最多打了多少局比赛 不可能则输出-1
题解:重点是考虑两人对k取余的结果
若余数不为零 则 对方的获胜场数一定大于零。考虑一下。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <map>
#define ll __int64
using namespace std;
int main()
{
ll k,a,b;
scanf("%I64d %I64d %I64d",&k,&a,&b);
ll ans=,ansa,ansb;
ans=a/k;
ansa=ans;
a=a%k;
ans+=(b/k);
ansb=b/k;
b=b%k;
if((ansb==&&a!=)||(ansa==&&b!=))
printf("-1\n");
else
printf("%I64d\n",ans);
return ;
}
2 seconds
512 megabytes
standard input
standard output
Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.
Let [n] denote the set {1, ..., n}. We will also write f: [x] → [y] when a function f is defined in integer points 1, ..., x, and all its values are integers from 1 to y.
Now then, you are given a function f: [n] → [n]. Your task is to find a positive integer m, and two functions g: [n] → [m], h: [m] → [n], such that g(h(x)) = x for all , and h(g(x)) = f(x) for all , or determine that finding these is impossible.
The first line contains an integer n (1 ≤ n ≤ 105).
The second line contains n space-separated integers — values f(1), ..., f(n) (1 ≤ f(i) ≤ n).
If there is no answer, print one integer -1.
Otherwise, on the first line print the number m (1 ≤ m ≤ 106). On the second line print n numbers g(1), ..., g(n). On the third line print m numbers h(1), ..., h(m).
If there are several correct answers, you may output any of them. It is guaranteed that if a valid answer exists, then there is an answer satisfying the above restrictions.
3
1 2 3
3
1 2 3
1 2 3
3
2 2 2
1
1 1 1
2
2
2 1
-1
题意:一个没有想出的构造题 给你长度为n的f(x) 构造 序列 g(n) h(m)
使得 m最小并且g(h(x)) = x , h(g(x)) = f(x)
题解:
g(h(x))= x
h(g(x)) = f(x)
h(g(h(x)))=f(h(x))
得h(x) = f(h(x))
继而得到f(x) = f(f(x))
h(m)为f(x)去重排序
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <map>
#define ll __int64
using namespace std;
int n;
int a[];
int g[];
int h[];
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
int be=;
memset(h,,sizeof(h));
for(int i=;i<=n;i++)
{
if(i==a[i])
{
g[be]=i;
h[i]=be;
be++;
}
}
for(int i=;i<=n;i++)
{
if(h[a[i]]==)
{
printf("-1\n");
return ;
}
}
printf("%d\n",be-);
for(int i=;i<=n;i++)
printf("%d ",h[a[i]]);
printf("\n");
for(int i=;i<be;i++)
printf("%d ",g[i]);
printf("\n");
return ;
}
Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) A B C D 水 模拟 构造的更多相关文章
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) F. Souvenirs 线段树套set
F. Souvenirs 题目连接: http://codeforces.com/contest/765/problem/F Description Artsem is on vacation and ...
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) E. Tree Folding 拓扑排序
E. Tree Folding 题目连接: http://codeforces.com/contest/765/problem/E Description Vanya wants to minimiz ...
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) D. Artsem and Saunders 数学 构造
D. Artsem and Saunders 题目连接: http://codeforces.com/contest/765/problem/D Description Artsem has a fr ...
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) C. Table Tennis Game 2 水题
C. Table Tennis Game 2 题目连接: http://codeforces.com/contest/765/problem/C Description Misha and Vanya ...
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) B. Code obfuscation 水题
B. Code obfuscation 题目连接: http://codeforces.com/contest/765/problem/B Description Kostya likes Codef ...
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) A. Neverending competitions 水题
A. Neverending competitions 题目连接: http://codeforces.com/contest/765/problem/A Description There are ...
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) E. Tree Folding
地址:http://codeforces.com/contest/765/problem/E 题目: E. Tree Folding time limit per test 2 seconds mem ...
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) D. Artsem and Saunders
地址:http://codeforces.com/contest/765/problem/D 题目: D. Artsem and Saunders time limit per test 2 seco ...
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) C - Table Tennis Game 2
地址:http://codeforces.com/contest/765/problem/C 题目: C. Table Tennis Game 2 time limit per test 2 seco ...
随机推荐
- linux学习总结----shell编程
## 环境变量 ## 全局变量 ``` 常见的全局环境变量 PATH 指令的搜索路径 HOME 用户的家目录 LOGNAME 登录名 SHELL 脚本的类型 使用全局环境变量 echo $PATH 自 ...
- 传入中文参数-->服务器_转码的方法
如果要传入 中文参数到 服务器 使用lr_convert_string_encoding() LR_ENC_SYSTEM_LOCALE , 转为 ...
- C++ 学习笔记之——STL 库 queue
1. 队列 queue 队列是一种容器适配器,专门用来满足先进先出的操作,也就是元素在容器的一端插入并从另一端提取. bool empty() const; 返回队列是否为空: size_type s ...
- C++ 学习笔记之——STL 库 vector
vector 是一种顺序容器,可以看作是可以改变大小的数组. 就像数组一样,vector 占用连续的内存地址来存储元素,因此可以像数组一样用偏移量来随机访问,但是它的大小可以动态改变,容器会自动处理内 ...
- 四:HDFS Snapshots
1.介绍 HDFS快照保存某个时间点的文件系统快照,可以是部分的文件系统,也可以是全部的文件系统.快照用来做数据备份和灾备.有以下特点: 1.快照几乎是实时瞬间完成的 2.只有在做快照时文件系统有修改 ...
- [leetcode-738-Monotone Increasing Digits]
Given a non-negative integer N, find the largest number that is less than or equal to N with monoton ...
- NProgress.js加载进度插件的简单实用方法
NProgress.js 说明: NProgress是基于jquery的,且版本要 >1.8 下载地址: https://github.com/rstacruz/nprogress API: N ...
- 爬取CVPR 2018过程中遇到的坑
爬取 CVPR 2018 过程中遇到的坑 使用语言及模块 语言: Python 3.6.6 模块: re requests lxml bs4 过程 一开始都挺顺利的,先获取到所有文章的链接再逐个爬取获 ...
- C++ Mooc学习
# C++远征篇之起航 1.IDE搭建,现在大部分同学都使用devC,devC的debug调试功能特别好用,可以跟踪变量.省去了在中间插入一些输出语句来输出中间变量的麻烦. 2.using names ...
- 关于char, wchar_t, TCHAR, _T(),L,宏 _T、TEXT,_TEXT、L
char :单字节变量类型,最多表示256个字符, wchar_t :宽字节变量类型,用于表示Unicode字符, 它实际定义在<string.h>里:typedef unsigned s ...