您的位置:首页 > 其它

Codeforces Round #365 (Div. 2)题解报告

2016-08-05 17:45 330 查看
此文章可以使用目录功能哟↑(点击上方[+])

cf毕竟比较晚,只能赛后写一下,D题有空再做吧...

链接→Codeforces Round #365 (Div. 2)




 Problem A - Mishka and Game

Accept: 0    Submit: 0

Time Limit: 1 second    Memory Limit : 256 megabytes




 Problem Description

Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.

Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round.
In case if player dice values are equal, no one of them is a winner.

In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.

Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!



 Input

The first line of the input contains single integer n n (1 ≤ n ≤ 100) — the number of game rounds.

The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≤ mi,  ci ≤ 6) — values on dice upper face after Mishka's and Chris' throws in i-th round respectively.



 Output

If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.

If Chris is the winner of the game, print "Chris" (without quotes) in the only line.

If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.



 Sample Input

3

3 5

2 1

4 2

2

6 1

1 6

3

1 5

3 3

2 2



 Sample Output

Mishka

Friendship is magic!^^

Chris



 Problem Idea

解题思路:

【题意】

Mishka和Chris轮流投掷骰子,点数大的人赢

在n轮游戏之后,谁赢的次数多,谁获得最终胜利;若一样多,则平局

【类型】

暴力

【分析】
Note

In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.

In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.

In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.

将输入的点数m,c进行比较,并记录两人赢的次数

最后将次数再比较一次即可

【时间复杂度&&优化】

O(n)

题目链接→Codeforces 703A Mishka and Game



 Source Code

/*Sherlock and Watson and Adler*/
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<complex>
#include<string>
#include<algorithm>
#include<iostream>
#define eps 1e-8
#define LL long long
#define bitnum(a) __builtin_popcount(a)
using namespace std;
const int N = 105;
const int M = 16;
const int inf = 1000000007;
const int mod = 110119;
int main()
{
int n,i,m,c,ans1=0,ans2=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d%d",&m,&c);
if(m>c)
ans1++;
else if(m<c)
ans2++;
}
if(ans1>ans2)
puts("Mishka");
else if(ans1<ans2)
puts("Chris");
else
puts("Friendship is magic!^^");
return 0;
}




 Problem B - Mishka and trip

Accept: 0    Submit: 0

Time Limit: 1 second    Memory Limit : 256 megabytes




 Problem Description

Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX — beautiful, but little-known northern country.

Here are some interesting facts about XXX:

XXX consists of n cities, k of whose (just imagine!) are capital cities.
All of cities in the country are beautiful, but each is beautiful in its own way. Beauty value of i-th city equals to ci.
All the cities are consecutively connected by the roads, including 1-st and n-th city, forming a cyclic route 1 — 2 — ... — n — 1. Formally, for every 1 ≤ i < n there is a road between i-th and i + 1-th city, and another one between 1-st and n-th city.
Each capital city is connected with each other city directly by the roads. Formally, if city x is a capital city, then for every 1 ≤ i ≤ n,  i ≠ x, there is a road between cities x and i.
There is at most one road between any two cities.
Price of passing a road directly depends on beauty values of cities it connects. Thus if there is a road between cities i and j, price of passing it equals ci·cj.

Mishka started to gather her things for a trip, but didn't still decide which route to follow and thus she asked you to help her determine summary price of passing
each of the roads in XXX. Formally, for every pair of cities a and b (a < b), such that there is a road between a and b you are to find sum of products ca·cb. Will you help her?



 Input

The first line of the input contains two integers n and k (3 ≤ n ≤ 100 000, 1 ≤ k ≤ n) — the number of cities in XXX and the number of capital cities among them.

The second line of the input contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 10 000) — beauty values of the cities.

The third line of the input contains k distinct integers id1, id2, ..., idk (1 ≤ idi ≤ n) — indices of capital cities. Indices are given in ascending order.



 Output

Print the only integer — summary price of passing each of the roads in XXX.



 Sample Input

4 1

2 3 1 2

3

5 2

3 5 2 2 4

1 4



 Sample Output

17

71



 Problem Idea

解题思路:

【题意】

n个城市(记为1~n)中有k个省会城市

下标相邻的两个城市之间有一条路,省会城市与除本城市外的其他城市均有一条路,两城市间最多只有一条直接相邻的路

每条路的价值为连接两城市的价值之积,比如道路连接城市i和j,那么该路的价值为c[i]*c[j]

问所有路的价值之和为多少

【类型】

数学技巧

【分析】

This image describes first sample case:



It is easy to see that summary price is equal to 17.

This image describes second sample case:



It is easy to see that summary price is equal to 71.

显然,此题的求解必须做到不重不漏才能正确

那么如何做到不重不漏呢?

首先,我们要学会如何将公式化简

对于从城市i出发的所有道路,假设有k条,它们通向城市p1,p2,……,pk

那么这些路的价值之和为



可见,我们可以先将价值之和处理出来

因为省会城市到其他城市均有路,且包含相邻下标城市之间的路

故我们可以优先处理省会城市

然后每处理一个省会城市,就将该城市的价值标0,这样就不会重复计算同一条路的价值

最终再把非省会城市且还没有处理的路算上就OK了

【时间复杂度&&优化】

O(n)

题目链接→Codeforces 703B Mishka and trip



 Source Code

/*Sherlock and Watson and Adler*/
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<complex>
#include<string>
#include<algorithm>
#include<iostream>
#define eps 1e-8
#define LL long long
#define bitnum(a) __builtin_popcount(a)
using namespace std;
const int N = 100005;
const int M = 16;
const int inf = 1000000007;
const int mod = 110119;
int c
;
int main()
{
int n,k,i,j,id;
__int64 ans=0,sum=0;
scanf("%d%d",&n,&k);
for(i=1;i<=n;i++)
{
scanf("%d",&c[i]);
sum+=c[i];
}
for(i=0;i<k;i++)
{
scanf("%d",&id);
sum-=c[id];
ans+=c[id]*sum;
c[id]=0;
}
c[0]=c
;
for(i=1;i<=n;i++)
ans+=c[i-1]*c[i];
printf("%I64d\n",ans);
return 0;
}




 Problem C - Chris and Road

Accept: 0    Submit: 0

Time Limit: 2 seconds    Memory Limit : 256 megabytes




 Problem Description

And while Mishka is enjoying her trip...

Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend.

Once walking with his friend, John gave Chris the following problem:

At the infinite horizontal road of width w, bounded by lines y = 0 and y = w, there is a bus moving, presented as a convex polygon of n vertices. The bus moves continuously with a constant speed of v in a straight Ox line in direction of decreasing x coordinates,
thus in time only x coordinates of its points are changing. Formally, after time t each of x coordinates of its points will be decreased by vt.

There is a pedestrian in the point (0, 0), who can move only by a vertical pedestrian crossing, presented as a segment connecting points (0, 0) and (0, w) with any speed not exceeding u. Thus the pedestrian can move only in a straight line Oy in any direction
with any speed not exceeding u and not leaving the road borders. The pedestrian can instantly change his speed, thus, for example, he can stop instantly.

Please look at the sample note picture for better understanding.

We consider the pedestrian is hit by the bus, if at any moment the point he is located in lies
strictly inside the bus polygon (this means that if the point lies on the polygon vertex or on its edge, the pedestrian is not hit by the bus).

You are given the bus position at the moment 0. Please help Chris determine minimum amount of time the pedestrian needs to cross the road and reach the point (0, w) and not to be hit by the bus.



 Input

The first line of the input contains four integers n, w, v, u (3 ≤ n ≤ 10 000, 1 ≤ w ≤ 10^9, 1 ≤ v,  u ≤ 1000) — the number of the bus polygon vertices, road width, bus speed and pedestrian speed respectively.

The next n lines describes polygon vertices in counter-clockwise order. i-th of them contains pair of integers xi and yi ( - 10^9 ≤ xi ≤ 10^9, 0 ≤ yi ≤ w) — coordinates of i-th polygon point. It is guaranteed that the polygon is non-degenerate.



 Output

Print the single real t — the time the pedestrian needs to croos the road and not to be hit by the bus. The answer is considered correct if its relative or absolute error doesn't exceed 10^(- 6).



 Sample Input

5 5 1 2

1 2

3 1

4 3

3 4

1 4



 Sample Output

5.0000000000



 Problem Idea

解题思路:

【题意】

一个凸多边形汽车,朝x轴负方向以速度v移动(意味着该凸多边形的每个顶点只有横坐标x会改变)

一个行人想从(0,0)到达(0,w),该行人可以以不超过u的任意速度在y轴上运动,可停止

问行人在不被汽车撞到的情况下,最快需要多少时间到达(0,w)

【类型】

二分+几何

【分析】

Following image describes initial position in the first sample case:



行人要到达(0,w)有两种情况:

①在汽车到达y轴前,行人已经经过碰撞点

这种情况下,行人可以全速前进,需要的时间为w/u

那么如何判断会不会被撞上呢?

因为点落在多边形内才算被撞上

那么枚举多边形的每个点(xi,yi),当行人以速度u到达yi时,此时该点已经经过y轴,说明行人无法在汽车到达y轴前经过碰撞点




②在汽车离开y轴后,行人经碰撞点到达(0,w)

因为行人到每个点的时间是不一样的,你在某个时间不会碰到多边形的某个点,但不能保证在下一个时间不会碰上多边形的另一个点

所以,我们采取二分时间判可行性,即二分行人需要等待汽车行驶的时间t

判可行性还是枚举多边形的每个点

若存在某点满足

,那么该时间t是不可行的

大致二分100次精度就差不多了

【时间复杂度&&优化】

O(logn)

题目链接→Codeforces 703C Chris and Road



 Source Code

/*Sherlock and Watson and Adler*/
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<complex>
#include<string>
#include<algorithm>
#include<iostream>
#define eps 1e-9
#define LL long long
#define bitnum(a) __builtin_popcount(a)
using namespace std;
const int N = 10005;
const int M = 16;
const int inf = 1000000007;
const int mod = 110119;
const int maxn=10050;
struct point
{
double x,y;
}p
;
double n,w,v,u;
int judge_sign(double x)
{
if(x>eps)
return 1;
if(x<-eps)
return -1;
return 0;
}
bool judge_before()
{
for(int i=0;i<n;i++)
if(judge_sign(u*p[i].x-v*p[i].y)<0)
return false;
return true;
}
bool judge_after(double t)
{
for(int i=0;i<n;i++)
if(judge_sign(u*p[i].x-v*p[i].y-u*v*t)>0)
return false;
return true;
}
int main()
{
int i;
scanf("%lf%lf%lf%lf",&n,&w,&v,&u);
for(i=0;i<n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
/*车到达y轴前,路人能到达(0,w)*/
if(judge_before())
{
printf("%.10f\n",w/u);
return 0;
}
/*车离开y轴后,路人能到达(0,w)*/
double l=0,r=1e9,mid;
for(i=0;i<100;i++)
{
mid=(l+r)/2;
if(judge_after(mid))
r=mid;
else
l=mid;
}
printf("%.10f\n",w/u+(l+r)/2);
return 0;
}

菜鸟成长记
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: