A. Bachgold Problem
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Bachgold problem is very easy to formulate. Given a positive integer n represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer k is called prime if it is greater than 1 and has exactly two positive integer divisors — 1 and k.
Input
The only line of the input contains a single integer n (2 ≤ n ≤ 100 000).
Output
The first line of the output contains a single integer k — maximum possible number of primes in representation.
The second line should contain k primes with their sum equal to n. You can print them in any order. If there are several optimal solution, print any of them.
Examples
input
5
output
2
2 3
input
6
output
3
2 2 2
题意:
其实这题意思就是找出 n 的素数的组成,如 6 可以有 3 个 2 (素数)组成。
思路:
这题的思路可以说有点流氓,其实仔细一想也是一种很聪明的写法,里面有 贪心 的思想。即把 n 打散成最小的元素(2),然后一个一个输出就可以了。
代码:
#include <stdio.h>
int main()
{
long long n;
scanf ("%lld",&n);
printf ("%lld\n",n/2);
while (n>3)
{
printf ("2 ");
n-=2;
}
printf ("%lld",n);
}
B. Parallelogram is Back
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Long time ago Alex created an interesting problem about parallelogram. The input data for this problem contained four integer points on the Cartesian plane, that defined the set of vertices of some non-degenerate (positive area) parallelogram. Points not necessary were given in the order of clockwise or counterclockwise traversal.
Alex had very nice test for this problem, but is somehow happened that the last line of the input was lost and now he has only three out of four points of the original parallelogram. He remembers that test was so good that he asks you to restore it given only these three points.
Input
The input consists of three lines, each containing a pair of integer coordinates xi and yi ( - 1000 ≤ xi, yi ≤ 1000). It’s guaranteed that these three points do not lie on the same line and no two of them coincide.
Output
First print integer k — the number of ways to add one new integer point such that the obtained set defines some parallelogram of positive area. There is no requirement for the points to be arranged in any special order (like traversal), they just define the set of vertices.
Then print k lines, each containing a pair of integer — possible coordinates of the fourth point.
Example
input
0 0
1 0
0 1
output
3
1 -1
-1 1
1 1
题意:
这题题意就是给出三个点的坐标,然后要求找到使其成为平行四边形的点的坐标及数量。
思路:
其实这题没什么思路可以讲,完全就是高中数学,甚至是初中数学题。根据所给的三个点的横竖坐标,进行平移,最后一定会得到符合条件的点,且符合的点数一定是三个。
代码:
#include <bits/stdc++.h>
using namespace std;
int a,b,c,d,e,f;
main()
{
cin>>a>>b>>c>>d>>e>>f;
cout<<3<<endl;
cout<<e+c-a<<" "<<f+d-b<<endl;
cout<<e+a-c<<" "<<f+b-d<<endl;
cout<<a+c-e<<" "<<b+d-f<<endl;
}