Codeforces Round #436 A. Fair Game】的更多相关文章

题意:给你n张卡片,上面写有数字,两个人选择两个数字,把相同数字的卡片都拿走,问能不能拿走所有的卡片并且两个人拿的卡片书相同. Examples Input 411272711 Output YES11 27 Input 266 Output NO Input 6102030201020 Output NO Input 6112233 Output NO 思路:水题啊,瞎搞搞记录一下就好了,看题太不仔细了,还以为每个人能拿多张卡片orz. 代码:#include<iostream>#inclu…
Codeforces Round #436 (Div. 2) 敲出一身冷汗...感觉自己宛如智障:( codeforces 864 A. Fair Game[水] 题意:已知n为偶数,有n张卡片,每张卡片上都写有一个数,两个人每人选一个数,每人可以拿的卡片必须写有是自己选的数,问能否选择两个数使得两个人每人拿的卡片数一样多并且能拿光卡片.[就是看输入是不是只有两种数字] //:第一遍我看成字符串包含有选的数字也能拿,,这样写着居然过了..水题水题.. #include<cstdio> #inc…
A. Fair Game 题目链接:http://codeforces.com/contest/864/problem/A 水题 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<stack> #include<map> #include<vector> #incl…
http://codeforces.com/contest/864/problem/C 题意: 坐标轴上有x = 0和 x = a两点,汽车从0到a之后掉头返回,从a到0之后又掉头驶向a...从0到a或者从a到0叫做一次旅行.汽车的油箱的容量为b,行驶1单位长度消耗的油量为1单位,在x = f处有一个加油站,可以把油加满. 现在,汽车位于x = 0处,将要进行k次旅行,开始汽车的油箱是满的,问至少要加多少次油才能走完全程,或者不可能时输出"-1". 思路: 可以把汽车的旅行看成是一直向…
http://codeforces.com/contest/864/problem/E 题意: 有一堆物品,每个物品有3个属性,需要的时间,失效的时间(一开始)和价值.只能一件一件的选择物品(即在选择这件物品时需要一定的时间,在这段时间之内不能选择其他物品),选择这件物品只能在失效时间之前选择.问选择的最大价值是多少. 思路: 对于每一个物品,有选和不选两种操作,与01背包是相似的.但是此题选择的顺序会影响到结果,这是01背包不同的地方. 比如 a.st = 3,a.en = 5,a.v = 4…
http://codeforces.com/contest/864 第一次打cf的月赛-- A 题意:给你一个数列,问你能不能保证里面只有两种数且个数相等.2<=n<=100,1<=ai<=100. 水--没看完题就交了结果YES的时候还要输出这两种数是什么,然后就+1了-- #include <iostream> #define maxn 105 using namespace std; int n,a,t[maxn],c[maxn],d[maxn]; int mai…
http://codeforces.com/contest/864/problem/D 题意: 给出n和n个数(ai <= n),要求改变其中某些数,使得这n个数为1到n的一个排列,首先保证修改字数最少,其次保证这个排列的字典序最小. 思路: 首先统计未出现过的数的个数,那么这个就是最小的改变次数. 将未出现过的数按升序存进一个数组C. 之后对于每一个数,如果这个数只出现过一次,那么就无法改变这个数. 如果一个数出现过大于一次,那么拿这个数x与C数组的第一个数字y比较,如果x<y 并且x未被标…
http://codeforces.com/contest/864/problem/B 题意: 给出一个字符串,要求找到一个集合S,使得从S中选出的所有数,在这些数的位置上的字母全部为小写且是不同的字母,并且任意在S中两个数i,j,对于i  <  j,从i到j的所有位置上都为小写字母. 思路: 找出所有的大写字母的位置,在任意两个"相邻"(指的是这两个大写字母的中间不存在大写字母)的大写字母中寻找S,这样就可以保证全部为小写字母,用set保存出现过的字母就可以了. 代码: #in…
D. Make a Permutation! time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input output: standard output Ivan has an array consisting of n elements. Each of the elements is an integer from 1 to n. Recently Ivan learned…
C. Bus time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input output: standard output A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches…
A. Fair Game time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Petya and Vasya decided to play a game. They have n cards (n is an even number). A single integer is written on each card. Befor…
题意:失火了,有n个物品,每个物品有价值pi,必须在时间di前(小于di)被救,否则就要被烧毁.救某个物 品需要时间ti,问最多救回多少价值的物品,并输出救物品的顺序. Examples Input 33 7 42 6 53 7 6 Output 1122 3 Input 25 6 13 3 5 Output 111 思路:有点像一个背包,dp数组记录的是当前时间所能获得的最大价值,转移方程dp[j]=max(dp[j],dp[j-t[i].ti]+t[i].w) path[i][j]表示到i号…
题意:给你n个数字,其中可能有相同的数字,要求你用其他的数字替换这些相同的数字,使得所得的序列字典序最小. Examples Input 43 2 2 3 Output 21 2 4 3 Input 64 5 6 3 2 1 Output 04 5 6 3 2 1 Input 106 8 4 6 7 1 6 3 4 5 Output 32 8 4 6 7 1 9 3 10 5 思路:暴力就好,那数组记录一下,注意:替换的时候要用比他小的换,如果选择了一个不换,那么后面的数就必须要换掉了. 代码:…
题意:一辆车在一条路上行驶,给你路的总长度a,油箱的容量b,加油站在距离起点的距离f,以及需要走多少遍这条路k(注意:不是往返) 问你最少加多少次油能走完. Examples Input 6 9 2 4 Output 4 Input 6 10 2 4 Output 2 Input 6 5 4 3 Output -1 思路:把需要走的路程拉直来看,那么相邻两次经过加油站之间的路程为2*f或2*(a-f),再加上一些特判就好了. 代码:#include<iostream>#include<s…
题意:给你一串长度为n的字符,由大小写字母组成,求连续的小写子串中不同字母个数的最大值. Input 11aaaaBaabAbA Output 2 Input 12zACaAbbaazzC Output 3 Input 3ABC Output 0 思路:水题,瞎搞搞就OK. 代码:#include<iostream>#include<string.h>#include<cmath>using namespace std; char s[250];int vis[30];…
题意:给你一个有向图,多次询问从一个点到另一个点字典序最小的路径上第k个点. 考虑枚举每一个点作为汇点(记为i),计算出其他所有点到i的字典序最小的路径.(当然,枚举源点也是可行的) 首先,我们建一张反向图,从i开始dfs,以删去所有无法到达i的点. 然后,因为此时图上所有点都可以到达i,所以可以贪心地在从每一个点出发的边中只保留终点编号最小的边,而把其他边删除. 这样就可以保证路径是字典序最小的,并且从每个点到i的路径只有一条. 而题目中给出了这样一种情况: there are paths f…
E. Fire time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Polycarp is in really serious trouble — his house is on fire! It's time to save the most valuable items. Polycarp estimated that it…
题意:给你一个长度为n的数组,每个元素都在1~n之间,要你改变最少的元素,使得它变成一个1~n的排列.在保证改动最少的基础上,要求字典序最小. 预处理cnt数组,cnt[i]代表i在原序列中出现的次数.b数组,代表没有出现过的数是哪些.b数组的长度就是答案. b数组是从小到大排好的,然后for循环b数组,同时用一个指针p指着a数组的当前位置,最开始指向开头,如果cnt[a[p]]==1,就向后跳,否则再看 是否b[i]<a[p]或者a[p]这个数是否已经出现过了(用个hav数组表示a[p]是否已…
传送门 题意 给出n种物品,抢救第\(i\)种物品花费时间\(t_i\),价值\(p_i\),截止时间\(d_i\) 询问抢救的顺序及物品价值和最大值 分析 按\(d_i\)排序的目的是防止以下情况 4 8 100 1 2 100 不排序只能选择第一个物品 (请仔细思考) 那么排序后做一遍背包,排序后选择顺序必定是递增的,求路径时从n往前找,具体见代码 code #include<bits/stdc++.h> using namespace std; #define ll long long…
Codeforces Round #485 (Div. 2) D. Fair 题目连接: http://codeforces.com/contest/987/problem/D Description Some company is going to hold a fair in Byteland. There are $n$ towns in Byteland and $m$ two-way roads between towns. Of course, you can reach any t…
Codeforces Round #272 (Div. 2) A. Dreamoon and Stairs time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Dreamoon wants to climb up a stair of n steps. He can climb 1 or 2 steps at each move.…
这场比赛没有打,后来补了一下,第五题数位dp好不容易才搞出来(我太菜啊). 比赛传送门:http://codeforces.com/contest/1073 A. Diverse Substring 题意:给你个字符串,让你找一个子串满足任意一个字符的个数不超过其他字符的总和,输出yes或no表示否存在,如果存在输出任意一个. 这题只要找两个不同的相邻字符,因为两个字符各一个都不超过其他字符的总和,如果字符串只由一个字符组成或长度等于一才会不存在. 代码如下: #include <iostrea…
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate it n = int(raw_input()) s = "" a = ["I hate that ","I love that ", "I hate it","I love it"] for i in ran…
Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/output 1 s, 256 MB    x3384 B Pyramid of Glasses standard input/output 1 s, 256 MB    x1462 C Vasya and String standard input/output 1 s, 256 MB    x1393…
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输出”#Color”,如果只有”G”,”B”,”W”就输出”#Black&White”. #include <cstdio> #include <cstring> using namespace std; const int maxn = 200; const int INF =…
 cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....       其实这个应该是昨天就写完的,不过没时间了,就留到了今天.. 地址:http://codeforces.com/contest/651/problem/A A. Joysticks time limit per test 1 second memory limit per test 256…
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard in…
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his info…
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Victor adores the sets theory. Let us remind you that a set is a group of…
题意: 思路: Codeforces Round #370(Solved: 4 out of 5) A - Memory and Crow 题意:有一个序列,然后对每一个进行ai = bi - bi + 1 + bi + 2 - bi + 3.... 的操作,最后得到了a 序列,给定 a 序列,求原序列. 思路:水. #include <set> #include <map> #include <stack> #include <queue> #includ…