Codeforces Round #450 (Div. 2) A-C题解

继续涨分,希望下次蓝名。

A. Find Extra One
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis.

Input

The first line contains a single positive integer n (2 ≤ n ≤ 105).

The following n lines contain coordinates of the points. The i-th of these lines contains two single integers xi and yi (|xi|, |yi| ≤ 109,xi ≠ 0). No two points coincide.

Output

Print "Yes" if there is such a point, "No" — otherwise.

You can print every letter in any case (upper or lower).

Examples
input
3
1 1
-1 -1
2 -1
output
Yes
input
4
1 1
2 2
-1 1
-2 2
output
No
input
3
1 2
2 1
4 60
output
Yes
Note

In the first example the second point can be removed.

In the second example there is no suitable for the condition point.

In the third example any point can be removed.

去除一个点后,剩下的点是否都在Y轴的一侧。

代码实现:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#include<cstdio>
#define ll long long
#define mset(a,x) memset(a,x,sizeof(a))

using namespace std;
const double PI=acos(-1);
const int inf=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1e6+5;
const int mod=1e9+7;
int dir[4][2]={0,1,1,0,0,-1,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}
ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}
struct point{
	int x,y;
}p[maxn];

int cmp(point a,point b)
{
	return a.x<b.x;
}

int main()
{
	int n,i,j,k;
	while(~scanf("%d",&n))
	{
		for(i=0;i<n;i++)
		scanf("%d%d",&p[i].x,&p[i].y);
		
		int ans1=0,ans2=0;
		for(i=0;i<n;i++)
		if(p[i].x<0)
		ans1++;
		else
		ans2++;
		
		if(ans1>=2&&ans2>=2)
		printf("No\n");
		else
		printf("Yes\n");
	}
	return 0;
}

B. Position in Fraction
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You have a fraction . You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point.

Input

The first contains three single positive integers abc (1 ≤ a < b ≤ 1050 ≤ c ≤ 9).

Output

Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1.

Examples
input
1 2 0
output
2
input
2 3 7
output
-1
Note

The fraction in the first example has the following decimal notation: . The first zero stands on second position.

The fraction in the second example has the following decimal notation: . There is no digit 7 in decimal notation of the fraction.


给定一个分数和k,问小数点后第一次出现k是在第几位,若不存在输出-1。

听说是UVA原题,我也没按原题找循环节,直接暴力小数点后200w位,成功水过。

代码实现:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#include<cstdio>
#define ll long long
#define mset(a,x) memset(a,x,sizeof(a))

using namespace std;
const double PI=acos(-1);
const int inf=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1e6+5;
const int mod=1e9+7;
int dir[4][2]={0,1,1,0,0,-1,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}
ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}

int main()
{
	int a,b,c;
	while(~scanf("%d%d%d",&a,&b,&c))
	{
		int flag=0;
		int ans=0;
		if(a>=b)
		a=a%b;
		for(int i=0;i<2000000;i++)
		{
			a*=10;
			int temp=a;
			temp=temp/b;
			a=a%b;
			ans++;
			if(temp==c)
			{
				flag=1;
				break;
			}
		}
		if(flag)
		printf("%d\n",ans);
		else
		printf("-1\n");
	}
	return 0;
}

C. Remove Extra One
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible.

We remind that in a sequence of numbers a1, a2, ..., ak the element ai is a record if for every integer j (1 ≤ j < i) the following holds:aj < ai.

Input

The first line contains the only integer n (1 ≤ n ≤ 105) — the length of the permutation.

The second line contains n integers p1, p2, ..., pn (1 ≤ pi ≤ n) — the permutation. All the integers are distinct.

Output

Print the only integer — the element that should be removed to make the number of records the maximum possible. If there are multiple such elements, print the smallest one.

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

In the first example the only element can be removed.


这个真没看懂什么意思,就贴上代码,祭奠一下做了一个半小时还没出来的C题。

代码实现:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<set>
#include<cstdio>
#define ll long long
#define mset(a,x) memset(a,x,sizeof(a))

using namespace std;
const double PI=acos(-1);
const int inf=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1e6+5;
const int mod=1e9+7;
int dir[4][2]={0,1,1,0,0,-1,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}
ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}
int dp[100005],map[100005],n;

void lcs()
{  
    dp[1] = 1;  
    int ans = 1;  
    for(int i = 1; i <= n; ++i){  
        dp[i] = 1;  
          
        for(int j = 1; j < i; ++j)
		{            
            if(map[i] > map[j])
			{  
                dp[i] = max(dp[i], dp[j] + 1);  
            }  
        }  
    }  
} 

int main()
{
	int i,j,k,x;
	while(~scanf("%d",&n))
	{
		mset(dp,0);
		int maxx=0,pre_maxx=0,ans_maxx=-inf,ans;
		for(i=0;i<n;i++)
		{
			scanf("%d",&x);
			if(x>maxx)
			{
				pre_maxx=maxx;
				maxx=x;
				dp[x]--;
			}
			else if(x>pre_maxx)
			{
				dp[maxx]++;
				pre_maxx=x;
			}
		}
		for(i=1;i<=n;i++)
		{
			if(dp[i]>ans_maxx)
			{
				ans=i;
				ans_maxx=dp[i];
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值