继续涨分,希望下次蓝名。
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.
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.
Print "Yes" if there is such a point, "No" — otherwise.
You can print every letter in any case (upper or lower).
3 1 1 -1 -1 2 -1
Yes
4 1 1 2 2 -1 1 -2 2
No
3 1 2 2 1 4 60
Yes
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;
}
You have a fraction . You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point.
The first contains three single positive integers a, b, c (1 ≤ a < b ≤ 105, 0 ≤ c ≤ 9).
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.
1 2 0
2
2 3 7
-1
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;
}
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.
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.
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.
1 1
1
5 5 1 2 3 4
5
In the first example the only element can be removed.
代码实现:
#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;
}