codeforces-703(好题)

题目链接:点击打开链接

A. Mishka and Game
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 m 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.

Examples
input
3
3 5
2 1
4 2
output
Mishka
input
2
6 1
1 6
output
Friendship is magic!^^
input
3
1 5
3 3
2 2
output
Chris
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.


题意:就是两个人掷色子比大小

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		int a,b,win1=0,win2=0;
		while(n--)
		{
			scanf("%d %d",&a,&b);
			if(a>b)	win1++;
			if(a<b)	win2++;
		}
		if(win1>win2)	puts("Mishka");
		if(win1<win2)	puts("Chris");
		if(win1==win2)	puts("Friendship is magic!^^");
	}
	return 0;
}


题目链接:点击打开链接

B. Mishka and trip
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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:

  1. XXX consists of n cities, k of whose (just imagine!) are capital cities.
  2. 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.
  3. 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.
  4. Each capital city is connected with each other city directly by the roads. Formally, if city x is a capital city, then for every1 ≤ i ≤ n,  i ≠ x, there is a road between cities x and i.
  5. There is at most one road between any two cities.
  6. 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 betweena 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.

Examples
input
4 1
2 3 1 2
3
output
17
input
5 2
3 5 2 2 4
1 4
output
71
Note

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.


题意:有n个城市,普通城市会和下一个城市有一条连线,省会城市 会与其他所有城市都有一条边,边的权值是两个城市权值的乘积,求所有边的权值之和!

思路:如第二个样例吧,省会城市有1和4,那么先算1相连的,用分配律计算是:a1*a2 + a1*a3 + a1*a4+a1*a5 = a1*T�n�qO �+a4+a5)所以可以先预处理一个权值之和,第一个城市相连边权值之和就是 (sum - a[1]) * a[1];计算城市4,计算要减去重复的,计算式是 (sum-a[1]-a[4])*a[4]  这就是规律了。这样算完后,会发现城市2还没有访问,所以可以在遍历一遍n个城市,找出未访问的城市,加上它即可

#include<cstdio>
#include<algorithm>
#include<cstring>
#define LL long long
using namespace std;
int n,k;
LL id[100010],c[100010],val[100010];
bool vis[100010];
int main()
{
	while(~scanf("%d %d",&n,&k))
	{
		LL sum=0;
		for(int i=1;i<=n;i++)
		{
			scanf("%I64d",&c[i]);
			sum+=c[i];
		}
		for(int i=1;i<=k;i++)
			scanf("%I64d",&id[i]);
		memset(vis,0,sizeof(vis));
		LL mark=0,ans=0;
		for(int i=1;i<=k;i++) // 从首都城市开始计算 
		{
			ans+=(sum-c[id[i]]-mark)*c[id[i]];
			mark+=c[id[i]];
			vis[id[i]]=1; // 每次标记 首都城市 和 首都城市的前驱城市 
			vis[id[i]==1?n:(id[i]-1)]=1;
		}
		for(int i=1;i<=n;i++)
		{
			if(vis[i])	continue;
			ans+=c[i]*c[i==n?1:(i+1)];
		}
		printf("%I64d\n",ans);
	}
	return 0;
}

题目链接:点击打开链接

C. Chris and Road
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 nvertices. 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 nwvu (3 ≤ n ≤ 10 0001 ≤ w ≤ 1091 ≤ 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 ( - 109 ≤ xi ≤ 109,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.

Example
input
5 5 1 2
1 2
3 1
4 3
3 4
1 4
output
5.0000000000
Note

Following image describes initial position in the first sample case:



这题开始以为很麻烦;看了别人的思路恍然大悟

题解:一共有三种情况:

①. 人以最大速度u前进时,汽车的速度很慢,任意一点都到达不了人的位置

②.人以最大速度u前行时,汽车的速度很快,在人达到之前汽车的任意一点都已经通过了y轴

③.人以最大速度u前进时,会与汽车相撞,需要调整速度躲避汽车


上面三种情况,①②两种都可以直接以最大速度u通过马路。对于第③种情况,我们可以在汽车最后一个通过y轴的点通过时行人恰好到达那个点的位置(如上图就是(0,3)),然后全速u走到终点。在过这个点之前,行人怎么变速的,我们就没必要考虑,反正他到达这个点的时间就是汽车完全通过这个点的时间,这样想来就好多了

#include<cstdio>
#include<algorithm>
using namespace std;
const int MAX=100010;
int n;
double x[MAX],y[MAX];
int main()
{
	double w,v,u;
	while(~scanf("%d %lf %lf %lf",&n,&w,&v,&u))
	{
		bool flag1=0,flag2=0;
		double ans=0;
		for(int i=0;i<n;i++)
		{
			scanf("%lf %lf",&x[i],&y[i]);
			if(x[i]/v<y[i]/u)	flag1=1;
			if(x[i]/v>y[i]/u)	flag2=1;
			ans=max(ans,x[i]/v+(w-y[i])/u); // 每次更新一下时间,遍历完所有的点 即可 
		}
		if(flag1+flag2==2) // 如果两个 flag 都被标记就满足第三种情况 
			printf("%.10lf\n",ans);
		else
			printf("%.10lf\n",w/u); // 只有一个点被标记,就是前两种情况 
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值