XUPT日常训练(个人)-4

A - Mishka and Game
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit  Status

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

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

Hint

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
#include  
#include  
#include  
#include  
#include   
#include  
#include 
using namespace std; 
int n;
 
int main()
{
	int t1,t2;
	int win1,win2;
	
	while(scanf("%d",&n)==1)
	{
		win1 = 0;
		win2 = 0;
		for(int i=1;i<=n;i++)
		{
			scanf("%d %d",&t1,&t2);
			if(t1>t2) 	
			{
				win1++;
				continue;
			}
			if(t2>t1) 
			{
				win2++;
				continue;
			}
		}
		if(win1 > win2)
		{
			printf("Mishka\n");
		}
		else if(win1



B - Mishka and trip
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit  Status

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:

  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 every 1 ≤ 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.

Sample Input

Input
4 1
2 3 1 2
3
Output
17
Input
5 2
3 5 2 2 4
1 4
Output
71

Hint

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.



#include
#include  
#include  
#include  
#include  
#include   
#include  
#include
#include

typedef  long long ll; 
using namespace std; 
ll n,k;
ll c[100005];
ll mid[100005];



int main()
{
	while(scanf("%lld %lld",&n,&k)==2)
	{
		ll re = 0;
		ll sum1 =0;
		memset(c,0,sizeof(c));
		memset(mid,0,sizeof(mid));
		for(int i=1;i<=n;i++)
		{
			scanf("%lld",&c[i]);
			sum1 += c[i];
		}
		
		for(int i=1;i<=k;i++)
		{
			scanf("%lld",&mid[i]);
		}
		
		for(int i=1;i<=k;i++)//先计算出首都到其他点的和 
		{
			re += (sum1-c[mid[i]])*c[mid[i]];
			sum1 -= c[mid[i]];    //防止首都间重复, 
			c[mid[i]] = 0;        //设置为0,防止相邻间重复 
		}
		
		for(int i=1;i










你可能感兴趣的:(ACM_比赛题目)