http://codeforces.com/contest/876/problem/A 题意: 一个人一天要吃n次蜂蜜,他有3个朋友,他第一次总是在一个固定的朋友家吃蜂蜜,如果说没有吃到n次,那么他就继续去另外的朋友家. 当他在一个朋友家吃的时候,另外的朋友家的蜂蜜就会恢复供应. 问这个人走的最小的距离. 一开始因为审题不清楚,忽略了第一次是固定的,所以wa了. 代码: #include <stdio.h> #include <algorithm> using namespace…
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,…
http://codeforces.com/contest/876/problem/D 题意: 最开始有一串全部由"O"组成的字符串,现在给出n个数字,指的是每次把位置n上的"O"变为"X",之后会进行扫描. 扫描的规则是如果遇到一个字符为"X"并且这个字符后面的字符为"O",那么就交换. 如果哪一次扫描没有发生交换,那么扫描就停止. 现在给出的n个数字,问第一次需要扫描多少次,第二次需要扫描多少次....…
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;…
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…
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.…
http://codeforces.com/contest/1064/problem/D 向上/向下加0,向左/右加1, step = 0,1,…… 求的是最少的步数,所以使用bfs. step=k -> step=k+1 1.step=k 使用一次左/右 到达 step=k+1 2.step=k+1 无限使用上下,得到所有 step=k+1 的状态 用dijkstra+堆优化 / spfa 超时. #include <bits/stdc++.h> using namespace std…
https://codeforces.com/contest/1064/problem/D 题意 给你一个有障碍的图,限制你向左向右走的次数,问你可以到达格子的个数 思路 可以定义状态为vi[x][y][l][r],状态唯一,理论上可以bfs或者dfs都可以搜出唯一结果,但是时间空间复杂度都不允许 进而要不改变状态定义或者找找规律或者思考贪心(调整访问顺序)在做这道题之前并不知道便利顺序对于搜索有这么大的影响 我尝试了重新定义状态为vi[x][y][dir],但是用了dfs还是wa 根本问题是,…
题目链接 A. Make a triangle! 题意 让某段最少增加多少使得构成三角形 思路 让较小两段往最长段去凑 代码 #include <bits/stdc++.h> #define DBG(x) cerr << #x << " = " << x << endl; using namespace std; int a[5]; int main(){ scanf("%d%d%d",&a[1],…
A: 题目大意:给你$a,b,c$三条边,可以给任意的边加任意的长度,求最少共加多少长度使得可以构成三角形 题解:排个序,若可以组成,输出$0$,否则输出$c-a-b+1(设a\leqslant b\leqslant c)$ 卡点:无 C++ Code: #include <cstdio> #include <algorithm> #include <cstring> #include <queue> inline int min(int a, int b)…
前言:依旧菜,\(A\)了\(4\)题,不过这次上蓝了挺开心的. A. Make a triangle! Description 给出\(3\)根木棍,希望用它们拼成三角形,可以将其中的某些木棍增长,求至少需要增长多少才能拼成一个三角形. Solution 水题,答案就是最长的木棍长度减去剩下两根木棍的长度和再\(+1\),如果为负则输出\(0\)(即本来就能拼成三角形). #include<cstdio> using namespace std; inline int re() { int…
Codeforces Round #486 (Div. 3) A. Diverse Team 题目连接: http://codeforces.com/contest/988/problem/A Description There are n students in a school class, the rating of the i-th student on Codehorses is ai. You have to form a team consisting of k students…
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.Anton and Danik Problems: 给你长度为N的,只含'A','D'的序列,统计并输出何者出现的较多,相同为"Friendship" Analysis: lucky_ji: 水题,模拟统计A和D的数目比较大小输出结果即可 Tags: Implementation B.Anton and Digits Problems: 给定k2个2,k3个3,k5个5及k6个6,可以组成若干个32或256,求所有方案中Sigma的最大值 Analysis: lucky_ji: 同…
链接:https://codeforces.com/contest/1133/problem/C 题意: 给n个数, 在这n个数中选最多n个数,来组成一个队伍. 保证这n个数的最大最小差值不大于5. 求最多能选几个数. 思路: 排序,二分,对每个数从后往前找比他差5的第一个数. 代码: #include <bits/stdc++.h> using namespace std; typedef long long LL; const int MAXN = 2e5 + 10; int a[MAXN…
#include <iostream> #include <algorithm> using namespace std; int main(){ int n,m; cin >> n >> m; ) || m > (n + )* ) cout<< -; else if( n>= m) { ; i < m; ++ i) cout<<"; "; }>=m){ ; i< m - n; ++…
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>…
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调了好久...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)…
题目链接 A. Trip for Meal 题意 三个点之间两两有路径,分别长为\(a,b,c\),现在从第一个点出发,走\(n-1\)条边,问总路径最小值. 思路 记起始点相邻的边为\(a,b\),相对的边为\(c\). 首先肯定走\(a,b\)中的最小值(不妨设为\(a\)),到达另一个顶点.那么这个顶点所连的两条边\(a,c\)中必然有一个是\(a,b,c\)三者中的最小值,否则最小值就为\(b\),与初始的选择矛盾. 于是接下来只需要在最小值的路上反复走即可. Code #include…
E. Mahmoud and a xor trip 题目连接: http://codeforces.com/contest/766/problem/E Description Mahmoud and Ehab live in a country with n cities numbered from 1 to n and connected by n - 1 undirected roads. It's guaranteed that you can reach any city from an…
地址:http://codeforces.com/contest/766/problem/E 题目: E. Mahmoud and a xor trip time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mahmoud and Ehab live in a country with n cities numbered from …
  题目链接:http://codeforces.com/contest/766/problem/E Examples input 3 1 2 3 1 2 2 3 out 10 题意: 给你一棵n个点的树,每个点有点权,求所有不同的路径异或和的总和 题解: DP 任选一个root,设定dp[i][j][0]为以i为最高点的路径异或和中,二进制上第j为分别是0,1的数量 记录答案 #include<bits/stdc++.h> using namespace std; #pragma comme…
题意: 给出n个数字,要求在这n个数中选出至少两个数字,使得它们的和在l,r之间,并且最大的与最小的差值要不小于x.n<=15 Problem - 550B - Codeforces 二进制 利用二进制, 第i位为1则加上a[i], 为0则不加, #include<iostream> #include <algorithm> #include <cmath> #include<map> using namespace std; typedef long…
A. Even Subset Sum Problem 题意 给出一串数,找到其中的一些数使得他们的和为偶数 题解 水题,找到一个偶数或者两个奇数就好了 代码 #include<iostream> #include<cstdio> #include<cstring> #define def 110 using namespace std; long a[def]; int main() { long _,ans0,ans1,ans2,n,i; for(scanf(&quo…
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…