这几天打了打codeforce,然后复习了下数位dp,树状dp与状态压缩dp,将之前不是很理解的题弄懂了。
星期一的cf半夜做,刚做完第一道题要敲第二题电脑就没电了,悲剧。。
CF Round #450
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<stdio.h>
using namespace std;
int main()
{
int n;
long long x,y;
long long a,b;
while(cin>>n)
{
a=0;
b=0;
while(n--)
{
scanf("%I64d%I64d",&x,&y);
if(x>0)
a++;
else
b++;
}
if(a==1||b==1||a==0||b==0)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
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<stdio.h>
#include<string.h>
using namespace std;
int a[100005][2];
int num[100005];
int dp[100005];
int main()
{
int n;
while(cin>>n)
{
num[0]=0;
a[0][0]=0;
a[0][1]=0;
memset(dp,0,sizeof(dp));
for(int i=1;i<=n;i++)
{
scanf("%d",&num[i]);
if(num[i]>=num[a[i-1][0]])
{
a[i][0]=i;
a[i][1]=a[i-1][0];
}
else if(num[i]>=num[a[i-1][1]])
{
a[i][0]=a[i-1][0];
a[i][1]=i;
}
else
{
a[i][0]=a[i-1][0];
a[i][1]=a[i-1][1];
}
if(num[i]>num[a[i-1][0]])
dp[i]=dp[i-1]+1;
else
dp[i]=dp[i-1];
}
int s=0;
int p=1;
int maxx=0;
for(int i=n;i>0;i--)
{
s=0;
for(int j=n;j>i;j--)
{
if(i==a[j-1][0])
{
if(num[j]>num[a[j-1][1]])
{
s++;
//cout<<"1当前j为:"<<j<<" 数值为:"<<num[j]<<" 之前最大值为:"<<num[a[j-1][1]]<<" s="<<s<<endl;
}
}
else
{
if(num[j]>num[a[j-1][0]])
{
s++;
// cout<<"2当前j为:"<<j<<" 数值为:"<<num[j]<<" 之前最大值为:"<<num[a[j-1][1]]<<" s="<<s<<endl;
}
}
}
int sum=dp[i-1];
if(s+sum==maxx)
{
if(num[i]<num[p])
p=i;
}
else if(s+sum>maxx)
{
maxx=s+sum;
p=i;
}
// cout<<s+sum<<" ";
/*if(i==1)
cout<<s+sum<<endl;
if(i==16)
cout<<s+sum<<endl;*/
}
// cout<<endl;
/* for(int i=1;i<=n;i++)
cout<<dp[i]<<" ";
cout<<endl<<endl;*/
cout<<num[p]<<endl;
// cout<<maxx<<endl;
}
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
#include<iostream>
using namespace std;
int main()
{
int a,b,c,s;
while(cin>>a>>b>>c)
{
s=-1;
for(int i=1;i<100000;i++)
{
a*=10;
if(a/b==c)
{
s=i;
break;
}
a%=b;
}
cout<<s<<endl;
}
return 0;
}