CODE FESTIVAL 2017 qual B
昨晚因为有点事就去忙了,没打后悔啊
A - XXFESTIVAL
Time limit : 2sec / Memory limit : 256MB
Score : 100 points
Problem Statement
Rng is going to a festival.
The name of the festival is given to you as a string S, which ends with FESTIVAL
, from input. Answer the question: "Rng is going to a festival of what?" Output the answer.
Here, assume that the name of "a festival of s" is a string obtained by appending FESTIVAL
to the end of s. For example, CODEFESTIVAL
is a festival of CODE
.
Constraints
- 9≤|S|≤50
- S consists of uppercase English letters.
- S ends with
FESTIVAL
.
Input
Input is given from Standard Input in the following format:
S
Output
Print the answer to the question: "Rng is going to a festival of what?"
Sample Input 1
CODEFESTIVAL
Sample Output 1
CODE
This is the same as the example in the statement.
Sample Input 2
CODEFESTIVALFESTIVAL
Sample Output 2
CODEFESTIVAL
This string is obtained by appending FESTIVAL
to the end of CODEFESTIVAL
, so it is a festival of CODEFESTIVAL
.
Sample Input 3
YAKINIKUFESTIVAL
Sample Output 3
YAKINIKU
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
int l=s.length()-;
for(int i=; i<l; ++i)
putchar(s[i]);
return ;
}
B - Problem Set
Time limit : 2sec / Memory limit : 256MB
Score : 200 points
Problem Statement
Rng is preparing a problem set for a qualification round of CODEFESTIVAL.
He has N candidates of problems. The difficulty of the i-th candidate is Di.
There must be M problems in the problem set, and the difficulty of the i-th problem must be Ti. Here, one candidate of a problem cannot be used as multiple problems.
Determine whether Rng can complete the problem set without creating new candidates of problems.
Constraints
- 1≤N≤200,000
- 1≤Di≤109
- 1≤M≤200,000
- 1≤Ti≤109
- All numbers in the input are integers.
Partial Score
- 100 points will be awarded for passing the test set satisfying N≤100 and M≤100.
Input
Input is given from Standard Input in the following format:
N
D1 D2 … DN
M
T1 T2 … TM
Output
Print YES
if Rng can complete the problem set without creating new candidates of problems; print NO
if he cannot.
Sample Input 1
5
3 1 4 1 5
3
5 4 3
Sample Output 1
YES
Sample Input 2
7
100 200 500 700 1200 1600 2000
6
100 200 500 700 1600 1600
Sample Output 2
NO
Not enough 1600s.
Sample Input 3
1
800
5
100 100 100 100 100
Sample Output 3
NO
Sample Input 4
15
1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
9
5 4 3 2 1 2 3 4 5
Sample Output 4
YES
用map看一下数据是否合法就行了
#include<bits/stdc++.h>
using namespace std;
map<int,int>M;
int main()
{
int n,m;
cin>>n;
for(int i=; i<n; i++)
{
int x;
cin>>x,M[x]++;
}
cin>>m;
int f=;
for(int i=; i<m; i++)
{
int x;
cin>>x;
if(!M[x])
{
f=;
break;
}
else M[x]--;
}
cout<<(f?"NO\n":"YES\n");
return ;
}
C - 3 Steps
Time limit : 2sec / Memory limit : 256MB
Score : 500 points
Problem Statement
Rng has a connected undirected graph with N vertices. Currently, there are M edges in the graph, and the i-th edge connects Vertices Ai and Bi.
Rng will add new edges to the graph by repeating the following operation:
- Operation: Choose u and v (u≠v) such that Vertex v can be reached by traversing exactly three edges from Vertex u, and add an edge connecting Vertices uand v. It is not allowed to add an edge if there is already an edge connecting Vertices u and v.
Find the maximum possible number of edges that can be added.
Constraints
- 2≤N≤105
- 1≤M≤105
- 1≤Ai,Bi≤N
- The graph has no self-loops or multiple edges.
- The graph is connected.
Input
Input is given from Standard Input in the following format:
N M
A1 B1
A2 B2
:
AM BM
Output
Find the maximum possible number of edges that can be added.
Sample Input 1
6 5
1 2
2 3
3 4
4 5
5 6
Sample Output 1
4
If we add edges as shown below, four edges can be added, and no more.
Sample Input 2
5 5
1 2
2 3
3 1
5 4
5 1
Sample Output 2
5
Five edges can be added, for example, as follows:
- Add an edge connecting Vertex 5 and Vertex 3.
- Add an edge connecting Vertex 5 and Vertex 2.
- Add an edge connecting Vertex 4 and Vertex 1.
- Add an edge connecting Vertex 4 and Vertex 2.
- Add an edge connecting Vertex 4 and Vertex 3.
搞成二分图然后dfs啊
然后再利用六哥的两边的个数想乘就好了
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+;
bool f=;
int c[N],cnt[];
vector<int>G[N];
void dfs(int x,int ff=)
{
if(c[x])
{
f|=ff!=c[x];
return;
}
c[x]=ff;
cnt[ff]++;
for(int u:G[x])
dfs(u,-ff);
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=; i<m; ++i)
{
int u,v;
scanf("%d%d",&u,&v);
G[u].push_back(v);
G[v].push_back(u);
}
dfs();
printf("%lld\n",f?1LL*n*(n-)/-m:1LL*cnt[]*cnt[]-m);
return ;
}
CODE FESTIVAL 2017 qual B的更多相关文章
- CODE FESTIVAL 2017 qual B B - Problem Set【水题,stl map】
CODE FESTIVAL 2017 qual B B - Problem Set 确实水题,但当时没想到map,用sort后逐个比较解决的,感觉麻烦些,虽然效率高很多.map确实好写点. 用map: ...
- CODE FESTIVAL 2017 qual B C - 3 Steps【二分图】
CODE FESTIVAL 2017 qual B C - 3 Steps 题意:给定一个n个结点m条边的无向图,若两点间走三步可以到,那么两点间可以直接连一条边,已经有边的不能连,问一共最多能连多少 ...
- 【题解】Popping Balls AtCoder Code Festival 2017 qual B E 组合计数
蒟蒻__stdcall终于更新博客辣~ 一下午+一晚上=一道计数题QAQ 为什么计数题都这么玄学啊QAQ Prelude 题目链接:这里是传送门= ̄ω ̄= 下面我将分几个步骤讲一下这个题的做法,大家不 ...
- Atcoder CODE FESTIVAL 2017 qual C D - Yet Another Palindrome Partitioning 回文串划分
题目链接 题意 给定一个字符串(长度\(\leq 2e5\)),将其划分成尽量少的段,使得每段内重新排列后可以成为一个回文串. 题解 分析 每段内重新排列后是一个回文串\(\rightarrow\)该 ...
- Atcoder CODE FESTIVAL 2017 qual C C - Inserting 'x' 回文串
题目链接 题意 给定字符串\(s\),可以在其中任意位置插入字符\(x\). 问能否得到一个回文串,若能,需插入多少个\(x\). 思路 首先统计出现次数为奇数的字符\(cnt\). \(cnt\ge ...
- Atcoder CODE FESTIVAL 2017 qual B E - Popping Balls 组合计数
题目链接 题意 \(A+B\)个球排成一行,左边\(A\)个为红球,右边\(B\)个为蓝球. 最开始可以选择两个数\(s,t\),每次操作可以取左起第\(1\)或\(s\)或\(t\)个球.问有多少种 ...
- Atcoder CODE FESTIVAL 2017 qual B D - 101 to 010 dp
题目链接 题意 对于一个\(01\)串,如果其中存在子串\(101\),则可以将它变成\(010\). 问最多能进行多少次这样的操作. 思路 官方题解 转化 倒过来考虑. 考虑,最终得到的串中的\(' ...
- Atcoder CODE FESTIVAL 2017 qual B C - 3 Steps 二分图
题目链接 题意 给定一个无向图,\(n\)个点,\(m\)条边(\(n,m\leq 1e5\)). 重复如下操作: 选择相异的两点u,v满足从点u出发走三条边恰好能到达点v.在这样的u,v点对之间添一 ...
- [Atcoder Code Festival 2017 Qual A Problem D]Four Coloring
题目大意:给一个\(n\times m\)的棋盘染四种颜色,要求曼哈顿距离为\\(d\\)的两个点颜色不同.解题思路:把棋盘旋转45°,则\((x,y)<-(x+y,x-y)\).这样就变成了以 ...
随机推荐
- 键盘各键对应的ASCII码值(包括鼠标和键盘所有的键)
ESC键 VK_ESCAPE (27)回车键: VK_RETURN (13)TAB键: VK_TAB (9)Caps Lock键: VK_CAPITAL (20)Shift键: VK_SHIFT ($ ...
- js当前日期
function CurentTime() { var now = new Date(); var year = now.getFullYear(); ...
- LR中变量、参数的使用介绍
Action(){ char * url = "www.baidu.com"; char arr_url[1024]; //将url变量的值复制给p_url1参数 lr_save_ ...
- C++11 function用法 可调用对象模板类
std::function<datatype()> ()内写参数类型 datatype 代表function的返回值 灵活的用法.. 代码如下 #include <stdio.h&g ...
- js判断是否为app
var ua = navigator.userAgent; var isapp = ua.match("lenovomallapp") == null ? 0 : 1;
- Feign-手动创建FeignClient
前言 在<Feign-请求不同注册中心的服务>中,提到,如果需要请求不同注册中心的服务,可以设置@FeignClient的url属性. 这种做法有个缺点,需要服务消费者,配置各个环境的ur ...
- Postgres-XL的限制
Postgres-XL是基于PostgreSQL的一个分布式数据库. 相比于PostgreSQL,XL的表的数据是可以分布到不同的datanode上的,对存在于不同的datanode上的数据进行处理, ...
- Linux 命令、配置文件及操作
Linux 命令.配置文件及操作 命令 命令 参数 说明 A alias.unalias 命令别名 B C cat 查看文件内容 cd 切换目录 chown 修改拥有着 chgrp 修改所属组 chm ...
- 利用wget 和 curl 监控网站是否正常
监控网站URL是否正常最常见的方法莫过于wget和curl命令了,这两个命令都是非常强大,参数也非常多,下面列举几个常用的参数. wget 常用命令参数:--spider ...
- python 面向对象基础和高级复习
面向对象基础 面向对象编程 面向过程编程:类似于工厂的流水线 优点:逻辑清晰 缺点:扩展性差 面向对象编程:核心是对象二字,对象属性和方法的集合体,面向对象编程就是一堆对象交互 优点:扩展性强 缺点: ...