http://codeforces.com/contest/876/problem/D 题意:题意真是难懂,就是给一串序列,第i次操作会在p[x](1<=x<=i)这些位置放上硬币,然后从左到右观察,如果第i个位置有硬币但第i+1个位置没有硬币,那么互换,然后继续从第i+1个硬币开始看.直到不需要交换,需要计算出到终极状态需要多少步. 思路: 模拟. #include<iostream> #include<algorithm> #include<cstring&g…
Codeforces Round #441 (Div. 2) codeforces 876 A. Trip For Meal(水题) 题意:R.O.E三点互连,给出任意两点间距离,你在R点,每次只能去相邻点,要走过n个点,求走过的最短距离. #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int main() { int n, a, b, c; scanf("…
Codeforces Round #441 (Div. 2) A. Trip For Meal 题目描述:给出\(3\)个点,以及任意两个点之间的距离,求从\(1\)个点出发,再走\(n-1\)个点的最短路径. solution 当\(n=1\)时,答案为\(0\),当\(n=2\)时,答案等于与开始点相连的两条边的最小值,当\(n>2\)时,答案等于与开始点相连的两条边的最小值+三条边最小值*\((n-2)\) 时间复杂度:\(O(1)\) B. Divisiblity of Differen…
上次打了一发 Round #440 Div.2 结果被垃圾交互器卡掉 $200$ Rating后心情复杂... 然后立了个 Round #441 要翻上蓝的flag QAQ 晚饭回来就开始搞事情, 大力安利了一发 Codeforces 然后成功拉到隔壁机房 $N$ 个 dalao 一起开黑 (垃圾 Codeforces 的 CAPTCHA 居然还要架梯子才能用...) 顺便备好 TIM 准备连线 UOJ 群 233 (算了不扯赛前了直接说赛中...) 开场开 $A$ 题, 一脸懵逼? (论 CF…
A. Trip For Meal Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses.…
题目链接 A. Trip for Meal 题意 三个点之间两两有路径,分别长为\(a,b,c\),现在从第一个点出发,走\(n-1\)条边,问总路径最小值. 思路 记起始点相邻的边为\(a,b\),相对的边为\(c\). 首先肯定走\(a,b\)中的最小值(不妨设为\(a\)),到达另一个顶点.那么这个顶点所连的两条边\(a,c\)中必然有一个是\(a,b,c\)三者中的最小值,否则最小值就为\(b\),与初始的选择矛盾. 于是接下来只需要在最小值的路上反复走即可. Code #include…
http://codeforces.com/contest/876/problem/D 题意: 最开始有一串全部由"O"组成的字符串,现在给出n个数字,指的是每次把位置n上的"O"变为"X",之后会进行扫描. 扫描的规则是如果遇到一个字符为"X"并且这个字符后面的字符为"O",那么就交换. 如果哪一次扫描没有发生交换,那么扫描就停止. 现在给出的n个数字,问第一次需要扫描多少次,第二次需要扫描多少次....…
A. Trip For Meal time limit per test 1 second memory limit per test 512 megabytes input standard input output standard output Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbi…
A. Combination Lock time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there…
A. Joysticks time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at…
https://codeforces.com/contest/1121/problem/D 题意 给你一个m(<=5e5)个数的序列,选择删除某些数,使得剩下的数按每组k个数以此分成n组(n*k<=m),存在只要一组满足和目标集合s(|s|<=k)匹配(即集合中存在的数,组内一定存在) 题解 重点:找出至少一组满足要求的数 假设[l,r]内满足要求,还需要满足:\((l-1)/k*k+(m-r)/k*k>=k*(n-1)\),可以用双指针,对于每个l可以处理出最小的r满足要求 这样…
A. Snacktower 题目连接: http://codeforces.com/contest/767/problem/A Description According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time n snacks of distinct s…
A. Gabriel and Caterpillar 题目连接: http://www.codeforces.com/contest/652/problem/A Description The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm fro…
链接:http://codeforces.com/contest/404/problem/B B. Marathon time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Valera takes part in the Berland Marathon. The marathon race starts at the stadium…
http://codeforces.com/contest/714/problem/C 题目大意:有t个询问,每个询问有三种操作 ①加入一个数值为a[i]的数字 ②消除一个数值为a[i]的数字 ③给一个字符串s,s中分别表示0和1,0表示目前该位为偶数,1表示目前该位为奇数.然后询问目前数组中和s每一位能匹配的个数.如果数组中目前的该数字比s的len要短,那么我们就在s的左边一直加0.如果数组中的目前的数字比s的len长,那么就在该数组的左边一直加0就好了.问能和s匹配的有几个,并输出 思路:我…
http://codeforces.com/contest/876/problem/C 题意: 现在有一个数n,它是由一个数x加上x每一位的数字得到的,现在给出n,要求找出符合条件的每一个x. 思路: n最大1e9,那么9个9最多才加81,所以最多枚举100次,就可以找到所有符合条件的数. 代码: #include <stdio.h> #include <string.h> #include <vector> using namespace std; vector<…
http://codeforces.com/contest/876/problem/B 题意: 给出n个数,要求从里面选出k个数使得这k个数中任意两个的差能够被m整除,若不能则输出no. 思路: 差能够被m整除,其实就是对m取余的余数相同.那么就统计n个数的余数丢到一个map里面,最后判断是否有某个数的数量大于等于k. 代码: #include <stdio.h> #include <map> #include <vector> using namespace std;…
http://codeforces.com/contest/876/problem/A 题意: 一个人一天要吃n次蜂蜜,他有3个朋友,他第一次总是在一个固定的朋友家吃蜂蜜,如果说没有吃到n次,那么他就继续去另外的朋友家. 当他在一个朋友家吃的时候,另外的朋友家的蜂蜜就会恢复供应. 问这个人走的最小的距离. 一开始因为审题不清楚,忽略了第一次是固定的,所以wa了. 代码: #include <stdio.h> #include <algorithm> using namespace…
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. Trip For Meal 题目链接:http://codeforces.com/contest/876/problem/A 题目意思:现在三个点1,2,3,1-2的路程是a,1-3的路程是b,2-3的路程是c,从1点开始,小熊维尼在1点吃过一次蜂蜜了,但是他要吃n次蜂蜜,每次他离开一个地方以后这个地方的蜂蜜就会自动补充,问最少需要走多少距离. 题目思路:如果n=1,那么就是0,如果n等于2,那么答案说就是min(a,b),如果n>2,答案就是min(a,b)+(n-2)*min(a,b,…
A. Coins 题目链接:https://codeforc.es/contest/1061/problem/A 题意: 给出n和s,要在1-n中选数(可重复),问最少选多少数可以使其和为s. 题解: 贪心就行了. 代码如下: #include <cstdio> #include <algorithm> #include <iostream> using namespace std; int main(){ int a,s; cin>>a>>s;…
B. Rebranding   The name of one small but proud corporation consists of n lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for th…
http://codeforces.com/contest/1154/problem/E 解题: 举例n=10,k=1 1,2,10,4,7,6,9,8,5,3 第一次,1队先挑2,10,4这三个人 1,2,10,4,7,6,9,8,5,3 第二次,2队挑6,9,8三个人 1,2,10,4,7,6,9,8,5,3 第三次,1队挑1,7,5三个人 1,2,10,4,7,6,9,8,5,3 第四次,2队挑3一个人 1,2,10,4,7,6,9,8,5, 显然需要实现的有两点 (1)挑完后的“连接”,…
题意:有一组数,问子数组和最大不超过\(t\)的最多元素个数. 题解:用数组模拟队列,不断的往里面放,队列中的元素之和大于\(t\),就不断地从队头弹出直到满足条件,维护一个最大值即可. 代码: int n,t; int a[N]; int q[N]; int hh,tt=-1; int main() { //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); n=read(),t=read(); for(int i=1;i<=n;++i) a…
A:显然答案与原数的差不会很大. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; #define ll long long char getc(){char c=getchar();while ((c<'A'||c>…
题目链接 题目大意:给你n个物品,第iii个物品价值aia_iai​,询问q次,问你能不能凑出价值为qiq_iqi​的物品. 小贪心吧.从大到小找,能拿就拿就行了. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mp make_pair #define pb push_back using namespace std; LL gcd(LL a,LL b){retur…
F - High Cry 题目大意:给你n个数,让你找区间里面所有数或 起来大于区间里面最大数的区间个数. 思路:反向思维,找出不符合的区间然后用总数减去.我们找出每个数掌控的最左端 和最右端,一个数的掌控区域为,这个区域里的或 为本身. 注意两个相同的数有可能掌控区域一样,记得将区域分段. #include<bits/stdc++.h> #define ll long long using namespace std; *1e5+; int n,a[N],l[N],r[N]; map<…
E. National Property time limit per test 1 second memory limit per test 512 megabytes input standard input output standard output You all know that the Library of Bookland is the largest library in the world. There are dozens of thousands of books in…
F. High Cry time limit per test 1 second memory limit per test 512 megabytes input standard input output standard output Disclaimer: there are lots of untranslateable puns in the Russian version of the statement, so there is one more reason for you t…
比赛的时候E调了好久...F没时间写T T A:直接走到短的路上来回走就好了 #include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> #include<cmath> #include<algorithm> using namespace std; ,inf=1e9; int n,a,b,c; inline void read(int &k)…