本文主要是介绍Codeforces Round #319 (Div. 2) (ABCE题解),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
比赛链接:http://codeforces.com/contest/577
Let's consider a table consisting of n rows and n columns. The cell located at the intersection of i-th row and j-th column contains number i × j. The rows and columns are numbered starting from 1.
You are given a positive integer x. Your task is to count the number of cells in a table that contain number x.
The single line contains numbers n and x (1 ≤ n ≤ 105, 1 ≤ x ≤ 109) — the size of the table and the number that we are looking for in the table.
Print a single number: the number of times x occurs in the table.
10 5
2
6 12
4
5 13
0
A table for the second sample test is given below. The occurrences of number 12 are marked bold.
题目分析:枚举约数判断
#include <cstdio>int main()
{int n, x, ans = 0;scanf("%d %d", &n, &x);for(int i = 1; i * i <= x; i ++){if(x % i == 0 && x / i <= n && i <= n){if(i * i == x)ans += 1;elseans += 2;}}printf("%d\n", ans);
}
time limit per test:2 seconds
memory limit per test:256 megabytes
You are given a sequence of numbers a1, a2, ..., an, and a number m.
Check if it is possible to choose a non-empty subsequence aij such that the sum of numbers in this subsequence is divisible by m.
The first line contains two numbers, n and m (1 ≤ n ≤ 106, 2 ≤ m ≤ 103) — the size of the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
3 5
1 2 3
YES
1 6
5
NO
4 6
3 1 1 3
YES
6 6
5 5 5 5 5 5
YES
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
题目大意:给n个数字,问存不存在一个子序列的和是m的倍数
题目分析:和POJ 1745差不多,主要是这题的n太大不能看二维,但是当前状态可以由之前的累计状态推出,所以开两个数组一个记录累计的余数,一个记录当前的余数,a[i] = true,表示当前状态出现余数为i的情况,然后累计给b数组,一旦b[0] = true,则退出
#include <cstdio>
#include <cstring>
int const MAX = 1e3 + 5;
bool a[MAX], b[MAX], flag;int main()
{int n, m;scanf("%d %d", &n, &m);flag = false;for(int i = 0; i < n; i++){int tmp;scanf("%d", &tmp);memset(a, false, sizeof(a));a[tmp % m] = true;for(int j = 0; j < m; j++){if(b[j]){a[tmp % m] = true;a[(tmp + j) % m] = true;}}for(int j = 0; j < m; j++){if(a[j])b[j] = a[j];if(b[0]){flag = true;break;}}if(flag)break;}printf("%s\n", flag ? "YES" : "NO");
}
Petya can ask questions like: "Is the unknown number divisible by number y?".
The game is played by the following rules: first Petya asks all the questions that interest him (also, he can ask no questions), and then Vasya responds to each question with a 'yes' or a 'no'. After receiving all the answers Petya should determine the number that Vasya thought of.
Unfortunately, Petya is not familiar with the number theory. Help him find the minimum number of questions he should ask to make a guaranteed guess of Vasya's number, and the numbers yi, he should ask the questions about.
A single line contains number n (1 ≤ n ≤ 103).
Print the length of the sequence of questions k (0 ≤ k ≤ n), followed by k numbers — the questions yi (1 ≤ yi ≤ n).
If there are several correct sequences of questions of the minimum length, you are allowed to print any of them.
4
3
2 4 3
6
4
2 4 3 5
The sequence from the answer to the first sample test is actually correct.
If the unknown number is not divisible by one of the sequence numbers, it is equal to 1.
If the unknown number is divisible by 4, it is 4.
If the unknown number is divisible by 3, then the unknown number is 3.
Otherwise, it is equal to 2. Therefore, the sequence of questions allows you to guess the unknown number. It can be shown that there is no correct sequence of questions of length 2 or shorter.
题目大意:两个人做游戏,A从1-n中选一个数字x,B通过询问一些数字对x的整除性判断x是什么(即该数字能不能被x整除),现在求B至少问多少次,每次问什么才能做到不管A从1-n中选的是哪个数字,他都能判断出来
题目分析:分析可以发现答案就是唯一分解后只有一种素数的数,证明可以通过唯一分解定理,脑补一下就好,注意0的时候只输出一个0
#include <cstdio>
int ans[1005];int main()
{int n, cnt = 0;scanf("%d", &n);for(int i = 2; i <= n; i++){bool flag = false;for(int j = 2; j <= i; j++){int tmp = i;while(tmp % j == 0){flag = true;tmp /= j;}if(tmp == 1)ans[cnt ++] = i;if(flag)break;}}printf("%d\n", cnt);for(int i = 0; i < cnt - 1; i++)printf("%d ", ans[i]);if(cnt)printf("%d\n", ans[cnt - 1]);
}
We call a hamiltonian path to be some permutation pi of numbers from 1 to n. We say that the length of this path is value .
Find some hamiltonian path with a length of no more than 25 × 108. Note that you do not have to minimize the path length.
The first line contains integer n (1 ≤ n ≤ 106).
The i + 1-th line contains the coordinates of the i-th point: xi and yi (0 ≤ xi, yi ≤ 106).
It is guaranteed that no two points coincide.
Print the permutation of numbers pi from 1 to n — the sought Hamiltonian path. The permutation must meet the inequality .
If there are multiple possible answers, print any of them.
It is guaranteed that the answer exists.
5
0 7
8 10
3 4
5 0
9 12
4 3 1 2 5
In the sample test the total distance is:
(|5 - 3| + |0 - 4|) + (|3 - 0| + |4 - 7|) + (|0 - 8| + |7 - 10|) + (|8 - 9| + |10 - 12|) = 2 + 4 + 3 + 3 + 8 + 3 + 1 + 2 = 26
题目大意:求一个排列,使得dist(pi, pi+1)的值小于等于25*10^8
题目分析:考虑把大坐标系竖直分成1000份,则竖直方向上最多走2*10^6*10^3 = 2e9,再考虑水平方向,再当前竖直块中最多移动2*1000次,从当前块移动到下一块最多走1000,一块中的移动就算3*1000,一共10^3块,因此水平最多走3e6,加起来肯定小于25e8,因此按纵坐标排序,给每块标号,当块标号为奇数时,从下往上,偶数时从上往下,画个图就看出来了
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
vector < pair<int, int> > vt[1005];int main()
{int n, x, y;scanf("%d", &n);for(int i = 1; i <= n; i++){scanf("%d %d", &x, &y);vt[x / 1000].push_back(make_pair(y, i));}for(int i = 0; i <= 1000; i++){sort(vt[i].begin(), vt[i].end());if(i & 1) reverse(vt[i].begin(), vt[i].end());int sz = vt[i].size();for(int j = 0; j < sz; j++)printf("%d ", vt[i][j].second);}printf("\n");
}
这篇关于Codeforces Round #319 (Div. 2) (ABCE题解)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!