1. 程式人生 > >Codeforces Round #185 (Div. 2)(解題報告)(ABC出DE補)

Codeforces Round #185 (Div. 2)(解題報告)(ABC出DE補)

第一次抽時間做一整套的cf ,可以說是心情複雜,D,E都是什麼神仙題目啊!!!

A   Whose sentence is it? (水題)

題目:

One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is.

Input

The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100.

Output

For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions.

Examples

Input

5
I will go to play with you lala.
wow, welcome.
miao.lala.
miao.
miao .

Output

Freda's
OMG>.< I don't know!
OMG>.< I don't know!
Rainbow's
OMG>.< I don't know!

解題報告A:題目的突破口比較容易找到,就是比較每個字串的前邊五位和最後五位分別是不是‘miao.'   'lala.' 在根據這個情況進行特殊輸出。

ac程式碼:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
typedef long long ll;

const int maxn=100000;


int main()
{
	int n;
	char str[maxn];
	char str1[1050];
	char str2[1050];
	scanf("%d",&n);
	getchar();
	while(n--)
	{
		gets(str);
		int len=strlen(str);
		int flag1=0,flag2=0;
		for(int i=0;i<5;i++)
		{
			str1[i]=str[i];
		}
		str1[5]='\0';
		for(int i=len-5,j=0;j<5;i++,j++)
		{
			str2[j]=str[i];
		}
		str2[5]='\0';
		if(strcmp(str1,"miao.")==0)
			flag1=1;
		if(strcmp(str2,"lala.")==0)
			flag2=1;
		if(flag1&&!flag2)
		{
			puts("Rainbow's");
		}
		else if(!flag1&&flag2)
		{
			puts("Freda's");
		}
		else
		{
			puts("OMG>.< I don't know!");
		}
	}		
	return 0;
} 

 B  Archer (思維)

 題目:

SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is  for SmallR while  for Zanoes. The one who shoots in the target first should be the winner.

Output the probability that SmallR will win the match.

Input

A single line contains four integers .

Output

Print a single real number, the probability that SmallR will win the match.

The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6.

Examples

Input

1 2 1 2

Output

0.666666666667

解題報告B: 這道題目就是一道概率問題轉化為數學中的等比數列求和的操作,其中a1=(a/b)  q=(1-a/b)*)1-(c/d) 得出最後的輸出公式就可以,需要注意的一點就是要eps小於1e-6,保持準確性精度。

ac程式碼:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
#define eps 1e-6
const int maxn =1e5+1000;

double ksm_double(double t,int n)
{
	double res=1;
	while(n)
	{
		if(n&1)
			res=res*t;
		t=t*t;
		n>>=1;
	}
	return res;
}
int a,b,c,d;
int main()
{
	while(scanf("%d%d%d%d",&a,&b,&c,&d)!=EOF)
	{
		double t1=a*1.0/b;
		double t2=c*1.0/d;
		double t3=(1-t1)*(1-t2);
		int cnt=1;
		while(1)
		{
			if(abs(ksm_double(t3,cnt))<eps)
				break;
			cnt++;
		}
		printf("%.12lf\n",t1*(1-ksm_double(t3,cnt))/(1-t3));
	}
	return 0;
}

C The Closest Pair (思維)

題目:

Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded.

The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is .

The pseudo code of the unexpected code is as follows:

input n
for i from 1 to n
    input the i-th point's coordinates into p[i]
sort array p[] by increasing of x coordinate first and increasing of y coordinate second
d=INF        //here INF is a number big enough
tot=0
for i from 1 to n
    for j from (i+1) to n
        ++tot
        if (p[j].x-p[i].x>=d) then break    //notice that "break" is only to be
                                            //out of the loop "for j"
        d=min(d,distance(p[i],p[j]))
output d

Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded.

You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded?

Input

A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109).

Output

If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point.

The conditions below must be held:

  • All the points must be distinct.
  • |xi|, |yi| ≤ 109.
  • After running the given code, the value of tot should be larger than k.

Examples

Input

4 3

Output

0 0
0 1
1 0
1 1

Input

2 100

Output

no solution

解題報告C:這道題目看似很複雜,其實就是尋找兩個最近的點,給定一個時間複雜度,問最後是否會超時(在程式執行的過程中),其實可以簡化操作,將二維的點的尋找轉化為一維的求解,假設所有點的橫座標都是相同的,縱座標的遞增的,所以每次尋找最近的兩個點的距離就是要將所有的點遍歷一遍,那麼時間複雜度其實是相同的,只要判斷這個過程的額所需要的時間和K的大小關係就可以了。

ac程式碼:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
#define eps 1e-6
const int maxn =1e5+1000;

int main()
{
	ll n,k;
	while(scanf("%lld%lld",&n,&k)!=EOF)
	{
		if(k>=(n*((ll)n-1)/2))
		{
			printf("no solution\n");
			continue;
		}	
		else
		{
			for(int i=0;i<n;i++)
				printf("1 %d\n",i);	
		}	
	}
}

 D Cats Transport (斜率dp)

題目:

Zxr960115 is owner of a large farm. He feeds m cute cats and employs p feeders. There's a straight road across the farm and n hills along the road, numbered from 1 to n from left to right. The distance between hill i and (i - 1) is di meters. The feeders live in hill 1.

One day, the cats went out to play. Cat i went on a trip to hill hi, finished its trip at time ti, and then waited at hill hi for a feeder. The feeders must take all the cats. Each feeder goes straightly from hill 1 to n without waiting at a hill and takes all the waiting cats at each hill away. Feeders walk at a speed of 1 meter per unit time and are strong enough to take as many cats as they want.

For example, suppose we have two hills (d2 = 1) and one cat that finished its trip at time 3 at hill 2 (h1 = 2). Then if the feeder leaves hill 1 at time 2 or at time 3, he can take this cat, but if he leaves hill 1 at time 1 he can't take it. If the feeder leaves hill 1 at time 2, the cat waits him for 0 time units, if the feeder leaves hill 1 at time 3, the cat waits him for 1 time units.

Your task is to schedule the time leaving from hill 1 for each feeder so that the sum of the waiting time of all cats is minimized.

Input

The first line of the input contains three integers n, m, p (2 ≤ n ≤ 105, 1 ≤ m ≤ 105, 1 ≤ p ≤ 100).

The second line contains n - 1 positive integers d2, d3, ..., dn (1 ≤ di < 104).

Each of the next m lines contains two integers hi and ti (1 ≤ hi ≤ n, 0 ≤ ti ≤ 109).

Output

Output an integer, the minimum sum of waiting time of all cats.

Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Examples

Input

4 6 2
1 3 5
1 0
2 1
4 9
1 10
2 10
3 12

Output

3

解題報告D:這道題目是自己搜尋題解的結果,因為自己進坑,想要貪心求解,但是後來題解說的是斜率dp。我連聽都沒有聽過。。。(= =) 放棄,以後會補。

E Fetch the Treasure(線段樹+spfa優化)

Rainbow built h cells in a row that are numbered from 1 to h from left to right. There are n cells with treasure. We call each of these n cells "Treasure Cell". The i-th "Treasure Cell" is the ai-th cell and the value of treasure in it is cidollars.

Then, Freda went in the first cell. For now, she can go just k cells forward, or return to the first cell. That means Freda was able to reach the 1st, (k + 1)-th, (2·k + 1)-th, (3·k + 1)-th cells and so on.

Then Rainbow gave Freda m operations. Each operation is one of the following three types:

  1. Add another method x: she can also go just x cells forward at any moment. For example, initially she has only one method k. If at some moment she has methods a1, a2, ..., ar then she can reach all the cells with number in form , where vi — some non-negative integer.
  2. Reduce the value of the treasure in the x-th "Treasure Cell" by y dollars. In other words, to apply assignment cx = cx - y.
  3. Ask the value of the most valuable treasure among the cells Freda can reach. If Freda cannot reach any cell with the treasure then consider the value of the most valuable treasure equal to 0, and do nothing. Otherwise take the most valuable treasure away. If several "Treasure Cells" have the most valuable treasure, take the "Treasure Cell" with the minimum number (not necessarily with the minimum number of cell). After that the total number of cells with a treasure is decreased by one.

As a programmer, you are asked by Freda to write a program to answer each query.

Input

The first line of the input contains four integers: h (1 ≤ h ≤ 1018), n, m (1 ≤ n, m ≤ 105) and k (1 ≤ k ≤ 104).

Each of the next n lines contains two integers: ai (1 ≤ ai ≤ h), ci (1 ≤ ci ≤ 109). That means the i-th "Treasure Cell" is the ai-th cell and cost of the treasure in that cell is ci dollars. All the ai are distinct.

Each of the next m lines is in one of the three following formats:

  • "1 x" — an operation of type 1, 1 ≤ x ≤ h;
  • "2 x y" — an operation of type 2, 1 ≤ x ≤ n, 0 ≤ y < cx;
  • "3" — an operation of type 3.

There are at most 20 operations of type 1. It's guaranteed that at any moment treasure in each cell has positive value. It's guaranteed that all operations is correct (no operation can decrease the value of the taken tresure).

Please, do not use the %lld specifier to read 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Output

For each operation of type 3, output an integer indicates the value (in dollars) of the most valuable treasure among the "Treasure Cells" Freda can reach. If there is no such treasure, output 0.

Examples

Input

10 3 5 2
5 50
7 60
8 100
2 2 5
3
1 3
3
3

Output

55
100
50

解題報告E:神仙題。。。不會。。。以後補上。。。