Codeforces 876C Classroom Watch:枚举】的更多相关文章

题目链接:http://codeforces.com/contest/876/problem/C 题意: 定义函数:f(x) = x + 十进制下x各位上的数字之和 给你f(x)的值(f(x) <= 1e9),让你输出所有可能的x值. 题解: 部分枚举. 考虑可能的x的范围: ∵ x < f(x) ∴ 十进制下x各位上的数字之和 < 9*9 ≍ 100 所以x枚举[f(x)-100, f(x)]之间的数就好了. AC Code: #include <iostream> #in…
题意:已知n,问满足条件"x的各个数字之和+x=n"的x有几个并按升序输出. 分析: 1.n最大1e9,10位数,假设每一位都为9的话,可知x的各个数字之和最大可以贡献90. 2.枚举n-90~90即可. #include<cstdio> #include<cstring> #include<cstdlib> #include<cctype> #include<cmath> #include<iostream> #…
codeforces 895A Pizza Separation 题目大意: 分成两大部分,使得这两部分的差值最小(注意是圆形,首尾相连) 思路: 分割出来的部分是连续的,开二倍枚举. 注意不要看成01背包,一定多读题 代码: #include <bits/stdc++.h> using namespace std; int a[800]; int main() { int n,minval,sum,tot; cin>>n; tot=0; for(int i=1;i<=n;+…
C. Classroom Watch time limit per test 1 second memory limit per test 512 megabytes input standard input output standard output Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on i…
https://codeforces.com/contest/1132/problem/C 枚举 + 差分前缀和 题意 有一段[1,n]的线段,有q个区间,选择其中q-2个区间,使得覆盖线段上的点最多为多少? 题解 一开始用贪心搞,搞到一半发现需要枚举的情况太多 只能用暴力搞,即枚举被去掉的两个区间,那么如何判断去掉哪两个区间比较好? 维护去掉后剩下的点数即答案 代码 #include<bits/stdc++.h> using namespace std; int n,q,i,j,l[5005…
Vasya and Beautiful Arrays CodeForces - 354C Vasya's got a birthday coming up and his mom decided to give him an array of positive integers a of length n. Vasya thinks that an array's beauty is the greatest common divisor of all its elements. His mom…
题意: 有两个点喷水,有很多个点有花,给出坐标. 求使得每个花都可以被喷到,两个喷水的半径的平方的和最小是多少. 思路: 枚举其中一个喷水的最大半径. 坑: 这题我贪心的思路有很大问题.一开始也是想这样枚举的,但是思路超级混乱,按照r2进行贪心但是最后想想想法很荒谬. 顺序和题意一定要搞的很透彻才可以== #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; struc…
题目链接: B. Skills time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was…
一个暴力的枚举,枚举组成正多边形需要对应覆盖原先的几条边,范围为(1,n/3),然后维护最大值就可以了,注意初始化为-inf. #include<stdio.h> #include<iostream> #include<string.h> #include<algorithm> using namespace std; ]; int main() { int n; while(~scanf("%d",&n)){ ; ;i<n…
The only difference between easy and hard versions is a number of elements in the array. You are given an array aa consisting of nn integers. The value of the ii-th element of the array is aiai. You are also given a set of mm segments. The jj-th segm…
Unlucky year in Berland is such a year that its number n can be represented as n = xa + yb, where a and b are non-negative integer numbers. For example, if x = 2 and y = 3 then the years 4 and 17 are unlucky (4 = 20 + 31, 17 = 23 + 32 = 24 + 30) and…
B. Tennis Game time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Petya and Gena love playing table tennis. A single match is played according to the following rules: a match consists of mult…
题意: 有 n个人,m个党派,第i个人开始想把票投给党派pi,而如果想让他改变他的想法需要花费ci元.你现在是党派1,问你最少花多少钱使得你的党派得票数大于其它任意党派. n,m<3000 思路: 枚举“除了党派1之外其他党派最多有的票的数量”,贪心一下即可 坑点: 1.爆int 2.inf太小,要设成0x3f3f3f3f3f3f3f3f 3.sort忘了从第一个开始排(被Wa7支配) #include<iostream> #include<iomanip> #include…
题目链接 思路如下 *题意: 给定一个序列,问有多少种方案可以将此序列分割成3个序列元素和完全相同的子序列.(子序列不能为空).即问有多少个点对(i,j)满足a[1]+-+a[i-1]=a[i]+a[i+1]+-+a[j]=a[j+1]+a[j+2]+-+a[n] 思路:这一题直接暴力求解就行了 看 n是否小于3 或者 数列元素之和 不能被3整除,如果是直接输出 0 当我们考虑某个位置 J 的时候,如果该位置的前缀和 sum[ J ] 是序列前缀和sum[ n ]的三分之二(此时剩下的区间的和一…
题目描述: C. Elections time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output As you know, majority of students and teachers of Summer Informatics School live in Berland for the most part of the year…
Link: Codeforces #196 传送门 A: 枚举 #include <bits/stdc++.h> using namespace std; #define X first #define Y second typedef long long ll; typedef pair<int,int> P; ; <<; int main() { scanf("%d%d",&n,&m); ;i<=m;i++) scanf(&…
C. time limit per test 1 second memory limit per test 512 megabytes input standard input output standard output Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number n.…
http://codeforces.com/contest/876/problem/C C. Classroom Watch time limit per test 1 second memory limit per test 512 megabytes input standard input output standard output Eighth-grader Vova is on duty today in the class. After classes, he went into…
题目链接:http://codeforces.com/problemset/problem/144/D 思路:首先spfa求出中心点S到其余每个顶点的距离,统计各顶点到中心点的距离为L的点,然后就是要统计在边上的点了,可以枚举边(这里边的数量最多也就100000条),对于枚举的某条边,如果它的其中某个端点到S的距离记过这条边,也就是满足一下这个条件:d1 + w == d2 || d2 + w == d1,那么边上符合要求的点最多只有一个,否则,就要判断d1,d2的关系,对于求出的边上的某个符合…
C. Anton and Making Potions 题目连接: http://codeforces.com/contest/734/problem/C Description Anton is playing a very interesting computer game, but now he is stuck at one of the levels. To pass to the next level he has to prepare n potions. Anton has a…
题目链接: http://codeforces.com/contest/435/problem/D D. Special Grid time limit per test:4 secondsmemory limit per test:256 megabytes 问题描述 You are given an n × m grid, some of its nodes are black, the others are white. Moreover, it's not an ordinary gri…
题目链接: http://www.codeforces.com/contest/666/problem/B 题意: 给你n个城市,m条单向边,求通过最短路径访问四个不同的点能获得的最大距离,答案输出一个满足条件的四个点. 题解: 首先预处理出任意两点的最短距离,用队列优化的spfa跑:O(n*n*logn) 现依次访问四个点:v1,v2,v3,v4 我们可以枚举v2,v3,然后求出v2的最远点v1,v3的最远点v4,为了保证这四个点的不同,直接用最远点会错,v1,v4相同时还要考虑次最远点来替换…
D. Spongebob and Squares Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/599/problem/D Description Spongebob is already tired trying to reason his weird actions and calculations, so he simply asked you to find all pairs of…
Problem B Bricks" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100002 Description The prisoner of the "IF" castle has decided to run away by disassembling the brick wall in his prison cell. To hide his work from his…
B. Which floor? time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how…
A. Mike and palindrome time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the s…
E. Simple Skewness time limit per test:3 seconds memory limit per test:256 megabytes input:standard input output:standard output Define the simple skewness of a collection of numbers to be the collection's mean minus its median. You are given a list…
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/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/problemset/problem/599/D 题意:给出一个数x,问你有多少个n*m的网格中有x个正方形,输出n和m的值. 思路: 易得公式为:$\sum_{i=0}^{n}(n-i)(m-i) $ 化简得:$\left [ n(n+1)-\frac{n(n+1)}{2}\right ]*m+\frac{n(n+1)(n+2)}{6}-\frac{n(n+1)}{2}*n$ 将n作为小的数,枚举n即可. #include<iostream> #i…