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:神仙题。。。不会。。。以后补上。。。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值