Bear and Displayed Friends time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his
A. Whose sentence is it? 代码: //codeforces 312 A //2013-05-01-19.12 #include <stdio.h> #include <stri
刚学算法竞赛(CP)的人都会遇到两个刷题网站:Codechef和Codeforces。在任何CP爱好者中,你都会发现其中一半赞成Codechef,而另一半倡导CodeForces。这场辩论有时会在Stackoverflow,Quora上白热化。
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 cha
A. Little C Loves 3 I time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Little C loves number «3» very much. He loves all things about it.
接下来n个数a1~an是男生送出的最小数量,然后是m个 b1~bm 是女生收到的最大数量。
首先考虑一个很显然的区间dp, $f[l][r][root]$表示$(l, r)$区间内,以$root$为根是否可行
A. 个数就不说了,第二个值 有多余的凑起来能再买一个就把还需要钱少的输出否则为0
题意:当前在看书的第 x 页,每次可以向前或者向后翻 d 页,这个书一共 n 页,问能否用最小操作翻到第 y 页。 题解:三种情况:1、直接翻能到的一定最短。 2、先翻到第一页,然后往后翻,翻到第 y 页。3、先翻到第 n 页,然后往前翻,翻到第 y 页。 #include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { int ans,t,n,x,y,d; cin >> t; while(
A. Juicer time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in
Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right.
H - Roads not only in Berland Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 25D Description Berland Government decided to improve relations with neighboring countries. First of all, i
The German University in Cairo (GUC) dorm houses are numbered from 1 to n. Underground water pipes connect these houses together. Each pipe has certain direction (water can flow only in this direction and not vice versa), and diameter (which characterizes the maximal amount of water it can handle).
A. Rebus time limit per test 1 second memory limit per test 256 megabytes input standard in
题意:题意是这样的,给你一个列向量b和行向量a,二者相乘ab,是一个nm的0,1矩阵,问你在这个矩阵里,有多少个不同的矩形,都有1组成,面积为k
A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-".
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
You are given a binary string s consisting of n zeros and ones.
Roma works in a company that sells TVs. Now he has to prepare a report for the last year.
In this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another.
A.取两边奇数偶数最小求和就行 //Codeforces Round 554A #include <bits/stdc++.h> #define ll long long using namespace std; const int maxn = 1e6+6; int main() { int oa=0,ob=0,ea=0,eb=0; int n,m,tp; scanf("%d %d",&n,&m); for(int i=0;i<n;i++){ scanf("%d",&tp); if(tp
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all n squad soldiers to line up on the parade ground.
Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size a i dollars.
再从lenb 开始枚举, ^s1[i-lenb]是消除上一个字符的影响, 因为 已经和 s1[i-lenb]做过异或运算,再来一次就是抵消了
水水的一道题,只需要找xy的最小公倍数,然后找a b区间有多少个可以被xy的最小公倍数整除的数,就是答案。
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
C. Watchmen time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possib
给你n, k,让你找n个数,这n个数的和可以被k整除,求这n个数中最大值的最小值。
A - Three Piles of Candies 题意:就是给了三堆糖,两个人,每人哪一堆,然后第三堆用来补充,最终要达到两个人的糖的数量一样多。 思路:水题,签到
A.暴力 #include <bits/stdc++.h> using namespace std; int a[1000005]; int main() { int n,x,y,mi=0; scanf("%d %d %d",&n,&x,&y); for(int i=1;i<=n;i++){ scanf("%d",&a[i]); } for(int i=1;i<=n;i++){ int fg = 1; for(int j=i-x;j<=i+y;j++){ if(j<1||j>n|
题意要求求出gcd(lcm(a_{i},a_{j})) | i<j,由于lcm(a_{i},a_{j})=a_{i}*a_{j}/gcd(a_{i},a_{j}),故得到式子gcd(a_{i}*a_{j}/gcd(a_{i},a_{j}))。接下来对式子进行化简。
The length of the longest common prefix of two strings s=s1s2…sn and t=t1t2…tm is defined as the maximum integer k (0≤k≤min(n,m)) such that s1s2…sk equals t1t2…tk.
很好的一道集合关系的题目,我比赛时用的是dfs,后来看到有人用并查集。 两种方法本质是一样的,但后者实现起来更方便,代码更简练。 /**************************************************** file name: cf.cpp author: huangjipeng creat time: 2014年09月21日 星期日 22时32分55秒 ***************************************************/
Alex doesn’t like boredom. That’s why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
题意描述 思路 AC代码 #include<bits/stdc++.h> #define x first #define y second #define PB push_back #define m
题意描述 思路 image.png AC代码 #include<bits/stdc++.h> #define x first #define y second #define PB push_back
The Doors 签到题 #include <iostream> using namespace std; int a[200005]; int main() { int n; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d",&a[i]); } int x=a[n-1]; int pos=n-2; for(int i=n-2;i>=0;i--) {
给定字符串,字符串中的问号表示可以自定义字母,字符串中是否只有一个abacaba的子串
题意:如果ai是素数,那么b中附加的就是第ai个素数,否则就是ai的最大公因数在bi中,
给你一串只有0和1的数字,然后对某一区间的数翻转1次(0变1 1变0),只翻转一次而且不能不翻转,然后让你计算最多可能出现多少个1。
构造题 最多可以是k的d次方的学生不成为朋友 循环节的长度以k为倍数翻倍 注意long long #include<iostream> #include<cstdio> #include<cstdlib> #include<string.h> #include<math.h> #include<algorithm> #include<vector> #include<queue> using namespace std; typedef long long ll; int main() { ll n
比较裸的二分,但是比赛的时候脑抽,用树状数组瞎搞过了,但是边界条件没注意让hack了。 后来看到有人写了很简单的版本,又过了一遍,提醒一下自己不能忘记基本算法。 #include<iostream> #include<cstdio> #include<cstdlib> #include<string.h> #include<math.h> #include<algorithm> #include<vector> #include<queue> using namespace std; typedef lon
给定一棵树,树的每个结点上有一个值,你可以对树上的值进行异或操作,求使树上的结点值成为目标值所需的最少操作
状压DP 学到一手,位操作时注意超出int用1LL进行位操作。 还有一个就是可以用排序从小到大进行降维。 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<vector> #include<math.h> #include<queue> using namespace std; struct node { long long m,num,can;//开始WA了后来丧心病狂全部改long
该文是关于Codeforces Round #234A的题目,介绍了该题的题意、解题思路以及代码实现。
有n个男孩和m个女孩,他们要结对跳舞,每对要有一个女孩和一个男孩,而且其中一个要求之前没有和其他人结对,求出最大可以结多少对。
比赛时就知道是树形dp但是和一般的熟悉的树形背包有区别。 dp[i][0]表示以i为根节点的树中没有黑色节点的数量。 dp[i][1]表示以i为根节点的树中有1个黑色节点的数量。 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<vector> #include<math.h> #include<queue> using namespace std; const int mod=1e9+7;
题意描述 思路 我们定义 [ [[0]为选择偶数的最大和,即最后一步是加法的最大和; [ ][1]为选择奇数的最大和,即最后一步是减法的最大和。得出转移方程: [ ][0]= ( [ −1][0],
我们可以反过来想,添k堵墙可以想成给cnt-k个空地构成的连通块打上标记,没有打上标记的即为空地
领取专属 10元无门槛券
手把手带您无忧上云