A. Bits Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/484/problem/A Description Let's denote as the number of bits set ('1' bits) in the binary representation of the non-negative integer x. You are given multiple queries…
A. Bits Let's denote as the number of bits set ('1' bits) in the binary representation of the non-negative integer x. You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≤ x ≤ r, and is m…
C. Necklace 题目连接: http://www.codeforces.com/contest/613/problem/C Description Ivan wants to make a necklace as a present to his beloved girl. A necklace is a cyclic sequence of beads of different colors. Ivan says that necklace is beautiful relative…
A. Array 题目连接: http://www.codeforces.com/contest/300/problem/A Description Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: The product of all numbers in the…
A. Two Substrings 题意:给一个字符串,求是否含有不重叠的子串"AB"和"BA",长度1e5. 题解:看起来很简单,但是一直错,各种考虑不周全,最后只能很蠢的暴力,把所有的AB和BA的位置求出来,能有一对AB和BA不重叠即可. #include <bits/stdc++.h> using namespace std; ]; vector<int> ab; vector<int> ba; int main() { w…
E. Sign on Fence Bizon the Champion has recently finished painting his wood fence. The fence consists of a sequence of n panels of 1 meter width and of arbitrary height. The i-th panel's height is hi meters. The adjacent planks follow without a gap…
D. Kindergarten Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/484/D Description In a kindergarten, the children are being divided into groups. The teacher put the children in a line and associated each child wi…
B. Maximum Value Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/484/problem/B Description You are given a sequence a consisting of n integers. Find the maximum possible value of (integer remainder of ai divided by aj), whe…
D. Handshakes Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/problem/D Description On February, 30th n students came in the Center for Training Olympiad Programmers (CTOP) of the Berland State University. They came one…
D. Kindergarten In a kindergarten, the children are being divided into groups. The teacher put the children in a line and associated each child with his or her integer charisma value. Each child should go to exactly one group. Each group should b…
D. Maximum Value You are given a sequence a consisting of n integers. Find the maximum possible value of (integer remainder of ai divided byaj), where 1 ≤ i, j ≤ n and ai ≥ aj. Input The first line contains integer n — the length of the sequence…
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin>>t; while(t--){ long long n,m; cin>>n>>m; ; ans=(n*(n+))>>;//总方案数(无论…
a. 给俩数, 求他俩之间二进制数中1最多的,有多个输出最小的: 贪心,从小到大加能加就加,最后可能碰到一个不能加了但是当前数比l小,那么就加上这个数,然后从大到小,能减就减,见到符合条件 #include<iostream> #include<stdio.h> #include<string.h> using namespace std; int main(){ long long n, l, r; ]; , maxa = 1e18; long long u; ;;…
这道题可以暴力的一直按要求的方法去做,做1000000次还不能整除m就认为永远不能整除m了(m不超过100000,循环1000000次比较安全了已经).这种方法可以AC. 下面深入的分析一下到底循环多少次就可以确定结果:首先有这样一个规律:(a+b)%c=(a%c+b%c)%c,那么这样其实这道题每次就是2*a.官方题解说的好: Production will stops iff exists integer K ≥ 0 such a·2K is divisible by m. From thi…
题意:有一个长度为偶数只含\(0\)和\(1\)的序列,你可以移除最多\(\frac{n}{2}\)个位置的元素,使得操作后奇数位置的元素和等于偶数位置的元素和,求新序列. 题解:统计\(0\)和\(1\)的个数,如果\(0\)的个数大于\(\frac{n}{2}\),那么直接输出\(n/2\)个\(0\),否则输出所有\(1\)(个数必须为偶). 代码: int t; int n; int a[N]; int main() { //ios::sync_with_stdio(false);cin…
当时打比赛的时候卡在D题了,没有看E.现在看来E还是不难的. 将n个数排序后,其实不排序也是可以的,只是排序能快一半的时间. 枚举前一半能得到多少种和,放到map里面: 然后在后一半数中枚举,然后在map里面查找. #include <bits/stdc++.h> using namespace std; typedef long long LL; ; LL a[maxn], f[maxn], S, ans; int n, m, k; map<int, LL> cnt[maxn];…