Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)
2017-09-05 22:04
513 查看
A. Arpa and a research in Mexican wave
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Arpa is researching the Mexican wave.
There are n spectators in the stadium, labeled from 1 to n.
They start the Mexican wave at time 0.
At time 1, the first spectator stands.
At time 2, the second spectator stands.
...
At time k, the k-th
spectator stands.
At time k + 1, the (k + 1)-th
spectator stands and the first spectator sits.
At time k + 2, the (k + 2)-th
spectator stands and the second spectator sits.
...
At time n, the n-th
spectator stands and the (n - k)-th spectator sits.
At time n + 1, the (n + 1 - k)-th
spectator sits.
...
At time n + k, the n-th
spectator sits.
Arpa wants to know how many spectators are standing at time t.
Input
The first line contains three integers n, k, t (1 ≤ n ≤ 109, 1 ≤ k ≤ n, 1 ≤ t < n + k).
Output
Print single integer: how many spectators are standing at time t.
Examples
input
output
input
output
input
output
Note
In the following a sitting spectator is represented as -, a standing spectator is represented as ^.
At t = 0 ----------
number
of standing spectators = 0.
At t = 1 ^---------
number
of standing spectators = 1.
At t = 2 ^^--------
number
of standing spectators = 2.
At t = 3 ^^^-------
number
of standing spectators = 3.
At t = 4 ^^^^------
number
of standing spectators = 4.
At t = 5 ^^^^^-----
number
of standing spectators = 5.
At t = 6 -^^^^^----
number
of standing spectators = 5.
At t = 7 --^^^^^---
number
of standing spectators = 5.
At t = 8 ---^^^^^--
number
of standing spectators = 5.
At t = 9 ----^^^^^-
number
of standing spectators = 5.
At t = 10 -----^^^^^
number
of standing spectators = 5.
At t = 11 ------^^^^
number
of standing spectators = 4.
At t = 12 -------^^^
number
of standing spectators = 3.
At t = 13 --------^^
number
of standing spectators = 2.
At t = 14 ---------^
number
of standing spectators = 1.
At t = 15 ----------
number
of standing spectators = 0.
A题,水。
B. Arpa and an exam about geometry
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points a, b, c.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old
position of b, and the new position of b is
the same as the old position of c.
Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not.
Input
The only line contains six integers ax, ay, bx, by, cx, cy (|ax|, |ay|, |bx|, |by|, |cx|, |cy| ≤ 109).
It's guaranteed that the points are distinct.
Output
Print "Yes" if the problem has a solution, "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
input
output
input
output
Note
In the first sample test, rotate the page around (0.5, 0.5) by
.
In the second sample test, you can't find any solution.
旋转之后重合,说明三个点到旋转点的距离相等。那么三点共圆。
设圆心为O,画图之后发现∠AOB=∠BOC。
则AB=BC。
判断一下就好了,除去共线的情况。
C. Five Dimensional Points
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n.
No two points coincide.
We will call point a bad if there are different points b and c,
not equal to a, from the given set such that angle between vectors
and
is
acute (i.e. strictly less than
).
Otherwise, the point is called good.
The angle between vectors
and
in
5-dimensional space is defined as
,
where
is
the scalar product and
is
length of
.
Given the list of points, print the indices of the good points in ascending order.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 103) —
the number of points.
The next n lines of input contain five integers ai, bi, ci, di, ei (|ai|, |bi|, |ci|, |di|, |ei| ≤ 103)
— the coordinates of the i-th point. All points are distinct.
Output
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
Examples
input
output
input
output
Note
In the first sample, the first point forms exactly a
angle
with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
We can see that all angles here are acute, so no points are good.
五维平面内有一些点,问哪些点和其他两点组成的夹角都为直角或者钝角。
在二维、三维空间当中,最多每个象限当中有1个点满足条件,点数大于4(二维)、8(三维)的时候,便不可能有符合要求的点。
如此合情推理,五维空间也一定有一个数,大于它时一定无解。
猜了个250,XJB AC。
直到现在也无法理解这样的正确性
线性代数都还给老师了。。。
D. Arpa and a list of numbers
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Arpa has found a list containing n numbers. He calls a list bad if and only if it is not empty and gcd (see
notes section for more information) of numbers in the list is 1.
Arpa can perform two types of operations:
Choose a number and delete it with cost x.
Choose a number and increase it by 1 with cost y.
Arpa can apply these operations to as many numbers as he wishes, and he is allowed to apply the second operation arbitrarily many times on the same number.
Help Arpa to find the minimum possible cost to make the list good.
Input
First line contains three integers n, x and y (1 ≤ n ≤ 5·105, 1 ≤ x, y ≤ 109) —
the number of elements in the list and the integers x and y.
Second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) —
the elements of the list.
Output
Print a single integer: the minimum possible cost to make the list good.
Examples
input
output
input
output
Note
In example, number 1 must be deleted (with cost 23)
and number 16 must increased by 1 (with
cost 17).
A gcd (greatest common divisor) of a set of numbers is the maximum integer that divides all integers in the set. Read more about gcd here.
一串数,对每个数,删除的代价是x, 数值+1的代价是y,求使所有数字gcd>1的最小代价。
对于每个数,要么删除,要么一直加直到它是gcd的倍数。
枚举gcd,则用筛法把素数筛出来,再枚举gcd为其中一个数字。
考虑对于一个固定的gcd,怎么计算最小代价。
对于(gcd*k,gcd*k+gcd]当中的数字,存在一个界限,此时删除和+1加到gcd*(k+1)的代价相同。设这个边界为f,
则x=y*((k+1)*gcd-f),对于每一个这样的区间都可以由此推出一个对应的f。
对于区间内小于 f 的数,把它们删去比较好。计算代价需要看这一段有多少个数,那么用cnt[i]表示比 i 小的数的个数,处理一下前缀和,可以方便地查询这一段有多少个数字。
对于大于等于 f 的数字,要把它们加到(k+1)*gcd.这时要计算代价,需要计算它们的和。同样用sum[i]表示小于 i 的数字的和,处理前缀和。
最后把所有区间的代价加起来,就是gcd固定为某个数时的代价。枚举所有可能的gcd,更新答案即可。
E题
博弈+状态压缩
http://blog.csdn.net/sinat_35406909/article/details/77898449
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Arpa is researching the Mexican wave.
There are n spectators in the stadium, labeled from 1 to n.
They start the Mexican wave at time 0.
At time 1, the first spectator stands.
At time 2, the second spectator stands.
...
At time k, the k-th
spectator stands.
At time k + 1, the (k + 1)-th
spectator stands and the first spectator sits.
At time k + 2, the (k + 2)-th
spectator stands and the second spectator sits.
...
At time n, the n-th
spectator stands and the (n - k)-th spectator sits.
At time n + 1, the (n + 1 - k)-th
spectator sits.
...
At time n + k, the n-th
spectator sits.
Arpa wants to know how many spectators are standing at time t.
Input
The first line contains three integers n, k, t (1 ≤ n ≤ 109, 1 ≤ k ≤ n, 1 ≤ t < n + k).
Output
Print single integer: how many spectators are standing at time t.
Examples
input
10 5 3
output
3
input
10 5 7
output
5
input
10 5 12
output
3
Note
In the following a sitting spectator is represented as -, a standing spectator is represented as ^.
At t = 0 ----------
number
of standing spectators = 0.
At t = 1 ^---------
number
of standing spectators = 1.
At t = 2 ^^--------
number
of standing spectators = 2.
At t = 3 ^^^-------
number
of standing spectators = 3.
At t = 4 ^^^^------
number
of standing spectators = 4.
At t = 5 ^^^^^-----
number
of standing spectators = 5.
At t = 6 -^^^^^----
number
of standing spectators = 5.
At t = 7 --^^^^^---
number
of standing spectators = 5.
At t = 8 ---^^^^^--
number
of standing spectators = 5.
At t = 9 ----^^^^^-
number
of standing spectators = 5.
At t = 10 -----^^^^^
number
of standing spectators = 5.
At t = 11 ------^^^^
number
of standing spectators = 4.
At t = 12 -------^^^
number
of standing spectators = 3.
At t = 13 --------^^
number
of standing spectators = 2.
At t = 14 ---------^
number
of standing spectators = 1.
At t = 15 ----------
number
of standing spectators = 0.
A题,水。
#include <cstdio> #include <iostream> #include <string.h> #include <string> #include <map> #include <queue> #include <vector> #include <set> #include <algorithm> #include <math.h> #include <cmath> #include <stack> #define mem0(a) memset(a,0,sizeof(a)) #define meminf(a) memset(a,0x3f,sizeof(a)) using namespace std; typedef long long ll; typedef long double ld; typedef double db; const int maxn=100005,inf=0x3f3f3f3f; const ll llinf=0x3f3f3f3f3f3f3f3f; const ld pi=acos(-1.0L); int main() { int n,k,t; cin >> n >> k >> t; if (t>=k&&t<=n) cout << k; else if (t<k) cout << t; else cout << n+k-t; return 0; }
B. Arpa and an exam about geometry
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points a, b, c.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old
position of b, and the new position of b is
the same as the old position of c.
Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not.
Input
The only line contains six integers ax, ay, bx, by, cx, cy (|ax|, |ay|, |bx|, |by|, |cx|, |cy| ≤ 109).
It's guaranteed that the points are distinct.
Output
Print "Yes" if the problem has a solution, "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
input
0 1 1 1 1 0
output
Yes
input
1 1 0 0 1000 1000
output
No
Note
In the first sample test, rotate the page around (0.5, 0.5) by
.
In the second sample test, you can't find any solution.
旋转之后重合,说明三个点到旋转点的距离相等。那么三点共圆。
设圆心为O,画图之后发现∠AOB=∠BOC。
则AB=BC。
判断一下就好了,除去共线的情况。
#include <cstdio> #include <iostream> #include <string.h> #include <string> #include <map> #include <queue> #include <vector> #include <set> #include <algorithm> #include <math.h> #include <cmath> #include <stack> #define mem0(a) memset(a,0,sizeof(a)) #define meminf(a) memset(a,0x3f,sizeof(a)) using namespace std; typedef long long ll; typedef long double ld; typedef double db; const ll llinf=0x3f3f3f3f3f3f3f3f; const ld pi=acos(-1.0L); ll sqr(ll x) { return x*x; } int main() { ll xa,xb,xc,ya,yb,yc; cin >> xa >> ya >> xb >> yb >> xc >> yc; if ((ya-yb)*(xb-xc)==(yb-yc)*(xa-xb)) { cout << "No"; return 0; } if (sqr(xb-xa)+sqr(yb-ya)==sqr(xc-xb)+sqr(yc-yb)) cout << "Yes"; else cout << "No"; return 0; }
C. Five Dimensional Points
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n.
No two points coincide.
We will call point a bad if there are different points b and c,
not equal to a, from the given set such that angle between vectors
and
is
acute (i.e. strictly less than
).
Otherwise, the point is called good.
The angle between vectors
and
in
5-dimensional space is defined as
,
where
is
the scalar product and
is
length of
.
Given the list of points, print the indices of the good points in ascending order.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 103) —
the number of points.
The next n lines of input contain five integers ai, bi, ci, di, ei (|ai|, |bi|, |ci|, |di|, |ei| ≤ 103)
— the coordinates of the i-th point. All points are distinct.
Output
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
Examples
input
6 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1
output
1 1
input
30 0 1 2 00 0 9 2 00 0 5 9 0
output
0
Note
In the first sample, the first point forms exactly a
angle
with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
We can see that all angles here are acute, so no points are good.
五维平面内有一些点,问哪些点和其他两点组成的夹角都为直角或者钝角。
在二维、三维空间当中,最多每个象限当中有1个点满足条件,点数大于4(二维)、8(三维)的时候,便不可能有符合要求的点。
如此合情推理,五维空间也一定有一个数,大于它时一定无解。
猜了个250,XJB AC。
直到现在也无法理解这样的正确性
线性代数都还给老师了。。。
#include <cstdio> #include <iostream> #include <string.h> #include <string> #include <map> #include <queue> #include <vector> #include <set> #include <algorithm> #include <math.h> #include <cmath> #include <stack> #define mem0(a) memset(a,0,sizeof(a)) #define meminf(a) memset(a,0x3f,sizeof(a)) using namespace std; typedef long long ll; typedef long double ld; typedef double db; const int maxn=1005,inf=0x3f3f3f3f; const ll llinf=0x3f3f3f3f3f3f3f3f; const ld pi=acos(-1.0L); int a[maxn][5]; bool f[maxn]; bool judge(int i,int j,int k) { int s=0; for (int p=1;p<=5;p++) s+=(a[i][p]-a[k][p])*(a[j][p]-a[k][p]); if (s<=0) return true; else return false; } int main() { int n,i,j,k; scanf("%d",&n); for (i=1;i<=n;i++) { for (j=1;j<=5;j++) scanf("%d",&a[i][j]); f[i]=1; } if (n>=250) { cout << 0; return 0; } for (i=1;i<=n;i++) { for (j=1;j<=n;j++) { if (j==i) continue; for (k=j+1;k<=n;k++) { if (k==i||k==j) continue; if (!judge(j,k,i)) f[i]=0; } } } int ans=0; for (i=1;i<=n;i++) { if (f[i]) ans++; } printf("%d\n",ans); for (i=1;i<=n;i++) { if (f[i]) printf("%d ",i); } return 0; }
D. Arpa and a list of numbers
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Arpa has found a list containing n numbers. He calls a list bad if and only if it is not empty and gcd (see
notes section for more information) of numbers in the list is 1.
Arpa can perform two types of operations:
Choose a number and delete it with cost x.
Choose a number and increase it by 1 with cost y.
Arpa can apply these operations to as many numbers as he wishes, and he is allowed to apply the second operation arbitrarily many times on the same number.
Help Arpa to find the minimum possible cost to make the list good.
Input
First line contains three integers n, x and y (1 ≤ n ≤ 5·105, 1 ≤ x, y ≤ 109) —
the number of elements in the list and the integers x and y.
Second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) —
the elements of the list.
Output
Print a single integer: the minimum possible cost to make the list good.
Examples
input
4 23 17 1 17 17 16
output
40
input
10 6 2
100 49 71 73 66 96 8 60 41 63
output
10
Note
In example, number 1 must be deleted (with cost 23)
and number 16 must increased by 1 (with
cost 17).
A gcd (greatest common divisor) of a set of numbers is the maximum integer that divides all integers in the set. Read more about gcd here.
一串数,对每个数,删除的代价是x, 数值+1的代价是y,求使所有数字gcd>1的最小代价。
对于每个数,要么删除,要么一直加直到它是gcd的倍数。
枚举gcd,则用筛法把素数筛出来,再枚举gcd为其中一个数字。
考虑对于一个固定的gcd,怎么计算最小代价。
对于(gcd*k,gcd*k+gcd]当中的数字,存在一个界限,此时删除和+1加到gcd*(k+1)的代价相同。设这个边界为f,
则x=y*((k+1)*gcd-f),对于每一个这样的区间都可以由此推出一个对应的f。
对于区间内小于 f 的数,把它们删去比较好。计算代价需要看这一段有多少个数,那么用cnt[i]表示比 i 小的数的个数,处理一下前缀和,可以方便地查询这一段有多少个数字。
对于大于等于 f 的数字,要把它们加到(k+1)*gcd.这时要计算代价,需要计算它们的和。同样用sum[i]表示小于 i 的数字的和,处理前缀和。
最后把所有区间的代价加起来,就是gcd固定为某个数时的代价。枚举所有可能的gcd,更新答案即可。
#include <cstdio>
#include <iostream>
#include <string.h>
#include <string>
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <stack>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
#define N 1000000using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
const int maxn=2000005,inf=0x3f3f3f3f;
const ll llinf=0x3f3f3f3f3f3f3f3f;
const ld pi=acos(-1.0L);
ll a[maxn],b[maxn],cnt[maxn],sum[maxn];
bool prime[maxn];
int num;
void init() {
num=0;
mem0(prime);
int i,j;
for (i=2;i<=N;i++) {
if (!prime[i])
a[++num]=i;
for (j=1;j<=num&&i*a[j]<=N;j++) {
prime[i*a[j]]=1;
if (i%a[j]==0)
break;
}
}
}
int main() {
int n,i,j;
ll x,y,ans,f,c;
scanf("%d%I64d%I64d",&n,&x,&y);
mem0(cnt);mem0(sum);
for (i=1;i<=n;i++) {
scanf("%I64d",&f);
sum[f]+=f;
cnt[f]++;
}
init();
for (i=1;i<=N*2;i++) {
sum[i]+=sum[i-1];
cnt[i]+=cnt[i-1];
}
ans=llinf;
for (i=1;i<=num;i++) {
c=0;
for (j=a[i];j-a[i]<=N;j+=a[i]) {
f=max(j-x/y-1,j-a[i]);
c+=(cnt[f]-cnt[j-a[i]])*x+((cnt[j]-cnt[f])*j-sum[j]+sum[f])*y;
}
ans=min(ans,c);
}
printf("%I64d\n",ans);
return 0;
}
E题
博弈+状态压缩
http://blog.csdn.net/sinat_35406909/article/details/77898449
相关文章推荐
- Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)C. Five Dimensional Points
- Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) D
- 【推导】Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) B. Arpa and an exam about geometry
- Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)C. Five Dimensional Points
- Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) A
- 【推导】【暴力】Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) C. Five Dimensional Points
- Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) B
- Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) C
- Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)C. Five Dimensional Points
- Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)C. Five Dimensional Points
- Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)C. Five Dimensional Points
- Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)C. Five Dimensional Points
- Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)C. Five Dimensional Points
- CF——Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)
- Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)C. Five Dimensional Points
- Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)C. Five Dimensional Points
- Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)
- Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)C. Five Dimensional Points
- Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)C. Five Dimensional Points
- 【前缀和】【枚举倍数】 Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) D. Arpa and a list of numbers