time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integ…
http://codeforces.com/problemset/problem/755/A 题意:给出一个n,让你找一个m使得n*m+1不是素数. 思路:暴力枚举m判断即可. #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <algorithm> #include <string> #include <iostr…
Hidden Code 题目连接: http://codeforces.com/gym/100015/attachments Description It's time to put your hacking skills to the test! You've been called upon to help crack enemy codes in the current war on... something or another. Anyway, the point is that yo…
A. ArielTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/A Description King Triton really likes watching sport competitions on TV. But much more Triton likes watching live competitions. So Triton decides to set up…
G. #TheDress Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/G Description After landing on planet i1c5l people noticed that blue and black clothes are quite popular among the locals. Each aboriginal has at least…
Couple Cover Time Limit: 3000MS   Memory Limit: 524288KB   64bit IO Format: %I64d & %I64u Description 方宝宝有n个篮球,每个篮球上写有一个值ai.他第一次从n个篮球中取出1个,不放回.第二次再在剩余的篮球中取出一个. (每个球被取概率相同).如果这两个球上的值的乘积大于等于p,他会变得高兴,然后请大家吃饭.否则方宝宝会不高兴, 然后暴食暴饮变得更胖. 当然为了方宝宝的健康(被请吃饭),我想取一个…
D. Jerry's Protest time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds. In each round, Andr…
题目链接: http://codeforces.com/contest/651/problem/D D. Image Preview time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya's telephone contains n photos. Photo number 1 is currently opened on…
原题链接:http://codeforces.com/gym/100203/attachments/download/1702/statements.pdf 题解 考虑暴力的复杂度是O(n^3),所以我们需要记录所有的ai+aj,如果当前考虑到了ak,那么就去前面寻找ai,使得ak-ai是我们记录过的和.整个算法的复杂度O(n^2). 代码 #include<iostream> #include<cstring> #include<cstdio> #include<…
Winter is here at the North and the White Walkers are close. John Snow has an army consisting of n soldiers. While the rest of the world is fighting for the Iron Throne, he is going to get ready for the attack of the White Walkers. He has created a m…
原题链接:http://codeforces.com/problemset/problem/850/A 题意:有n个五维空间内的点,如果其中三个点A,B,C,向量AB,AC的夹角不大于90°,则点A是“bad”的否则是“good”.题目让我们输出good的点. 思路:从2,3维空间超过5,7个点时不存在“good”的点,可以简单推知五维空间内,超过11个点时不存在“good”的点,那么点数小于11时暴力,大于11时输出0. 其实由于数据量小,直接暴力也是可行的. AC代码: #include<i…
http://codeforces.com/problemset/problem/749/C 题意:有n个人投票,分为 D 和 R 两派,从1~n的顺序投票,轮到某人投票的时候,他可以将对方的一个人KO,被KO的人不能投票了,这样循环,直到某一派的人全部被KO,问哪方赢. 思路:模拟..代码好懂.. #include <cstdio> #include <algorithm> #include <iostream> #include <cstring> #i…
题意:给定 n 个数,问你从有多少下标 i < j,并且 ai + aj 是2的倍数. 析:方法一: 从输入开始暴力,因为 i < j 和 i > j 是一样,所以可以从前面就开始查找,然后计数,用个map就搞定,不过时间有点长,接近两秒. 方法二: 先排序,然后暴力,暴力的原则是找前面的,也是用map查找,时间62ms. 代码如下: #include <cstdio> #include <string> #include <cstdlib> #inc…
C. PolandBall and Forest time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graph…
D. PolandBall and Polygon time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. P…
PolandBall and Gifts 转换成置换群后, 对于最大值我们很好处理. 对于最小值, 只跟若干个圈能否刚好组能 k 有关. 最直观的想法就是bitset优化背包, 直接搞肯定T掉. 我们能再发掘一些性质, 就是本质不能的圈的大小最多有sqrt(n)个, 因为1 + 2 + 3 ... + n = (n + 1) * n / 2 所以对于每个不同的数二进制优化一下就可以过啦. 感觉这种题就很有意思.. #include<bits/stdc++.h> #define LL long…
题目链接: https://vjudge.net/problem/1735275/origin 基本思路: 本题思路比较简单,首先,我们知道 a & x = b, b & x = b; 所以,一个数通过与运算改变只能改变一次! 所以,这里就有一种暴力的写法,三次for循环,时间复杂度是O(3n). 第一次,从1到n遍历一遍,计算各个元素出现的次数,如果大于等于2,则输出0,结束. 第二次,从1到n遍历,如果存在 vis[ a[i]&k ] >= 2 并且 与k与运算后的值与之…
D. Diverse Garland time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ii-th lamp is sisi ('…
D1. Magic Powder - 1 time limit per test: 1 second memory limit per test: 256 megabytes input: standard input output: standard output This problem is given in two versions that differ only by constraints. If you can solve this problem in large constr…
题意 给出一个二进制数\(n\),每次操作可以将一个整数\(x\)简化为\(x\)的二进制表示中\(1\)的个数,如果一个数简化为\(1\)所需的最小次数为\(k\),将这个数叫做特殊的数, 问从\(1\)到\(n\)一共有多少个特殊的数,答案对\(1e9+7\)取模. 分析 \(n\)最大为\(2^{1000}\),二进制表示中最多有\(1000\)个\(1\),所以\(n\)以内的数经过一次简化后将变为\(1000\)以内的数,我们可以暴力打表\(1000\)以内的数简化为\(1\)所需的最…
B. Shopping 题目连接: http://www.codeforces.com/contest/665/problem/B Description Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online. The store contains k items.…
题目链接:Codeforces 460E Roland and Rose 题目大意:在以原点为圆心,半径为R的局域内选择N个整数点,使得N个点中两两距离的平方和最大. 解题思路:R最大为30.那么事实上距离圆心距离最大的整数点只是12个最多,直接暴力枚举. #include <cstdio> #include <cstring> #include <vector> #include <algorithm> using namespace std; struc…
题意:给定一个正整数数组,求最长的区间,使得该区间内存在一个元素,它能整除该区间的每个元素. 析:暴力每一个可能的区间,从数组的第一个元素开始考虑,向两边延伸,设延伸到的最左边的点为l, 最右边的点为r.那么我们下一点考虑r+1即可, 因为[l, r]之间不会有更优解. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string>…
题目链接: http://codeforces.com/contest/665/problem/C 题意: 改变最少的字符,使得最终序列无相同的连续的字符. 分析: 对每一个与前一个字符相同的字符,枚举满足条件的字符进行替换. 代码: #include<iostream> using namespace std; int main (void) { string s;cin>>s; int n = s.length(); for(int i = 1; i < n; i++){…
题意:给定 n 个数,可以对所有的数进行缩小,问你找出和最大的数,使得这些数都能整除这些数中最小的那个数. 析:用前缀和来做,先统计前 i 个数中有有多少数,然后再进行暴力去找最大值,每次都遍历这一段就好. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #inclu…
链接 Codeforces 677D Vanya and Treasure 题意 n*m中有p个type,经过了任意一个 type=i 的各自才能打开 type=i+1 的钥匙,最初有type=1的钥匙, 问拿到type=p的钥匙最少需要走多少步 思路 第一想法就是按type来递推, 将type相同的存到一起,dp[i][j]=min(dp[i][j], dp[k][l]+distance([i][j], [k][l])),其中 a[i][j] = a[k][l]+1. 但这样type相同的个数…
题目链接:http://codeforces.com/contest/755/problem/D 题意:一个n边形,从1号点开始,每次走到x+k的位置如果x+k>n则到x+k-n的位置,问每次留下来的路径把这个多边形划分成了几个部分. 很明显只要求x到x+k位置之间的点有几个入度就行了,而且只要求小区间内除去两点剩下的点的入度即可. 不需要考虑x或x+k点到该点的入度因为更本不可能从x或x+k到该点. 所以可以将k值稍微优化一下全都统一到k<n/2,这不影响结果因为假设5个点1到3,k=2.5…
题目描述: In this problem we consider a very simplified model of Barcelona city. Barcelona can be represented as a plane with streets of kind x=cx=c and y=cy=c for every integer cc (that is, the rectangular grid). However, there is a detail which makes B…
A 水题 /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) using namespace std; typedef long long ll; typedef unsigned long long ull; ][] = {{, }, {, }, {, -}, { -, }, {, }, {, -}, { -, -}, { -, }}; , gakki = + + + + 1e9; , MAXM =…
题意: 给你两个01串,要你选n/2个位置,使得选的位置在s1中"1"的数量等于未选的s2中"1"的数量 n<=5000,1s 思路: 设两个串中出现"00""01""10""11"的总数是A,B,C,D,我们选的个数分别是a,b,c,d 数据最多能承受n^2的暴力 根据题意,有a+b+c+d=n/2     ① c+d=B-b+D-d    ② 联立得d=B+D+a-n/2 于是…