第十六周周四总结

  这几天打了打codeforce,然后复习了下数位dp,树状dp与状态压缩dp,将之前不是很理解的题弄懂了。

  星期一的cf半夜做,刚做完第一道题要敲第二题电脑就没电了,悲剧。。

  CF Round #450 

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
#include
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"<

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.


这题卡在15组样例超时。。。改了好几种方法还是超时。。。

//本题还未通过,待改正后再修改
#include
#include
#include
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为:"<
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 a, b, c (1 ≤ a < b ≤ 105, 0 ≤ 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

这道题我还想了半天怎么做,结果暴力就可以。。。
#include
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<




你可能感兴趣的:(水题,日常)