Codeforces Round #332 (Div. 2)

好菜,不说话了,说题。

A - Patrick and Shopping

从一个点出发,要经过其他两个点,然后回到原地,求最小时间花费。只有四种情况,从中选一个最小的就行了。

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[]) {
    // insert code here...
    int a,b,c;
    cin>>a>>b>>c;
    int ans=a+b+c;
    ans=min(2*a+2*b,ans);
    ans=min(2*a+2*c,ans);
    ans=min(2*b+2*c,ans);
    cout<<ans<<endl;
    return 0;
}

B - Spongebob and Joke

这题,思路还是很简单,唯一要注意的是,当有多种情况和不可能同时发生时,输出不可能。 这里被HACK了。。。

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;

int f[100100],d[100100];
int mark[100100];
int mylink[100100];

int main(int argc, const char * argv[]) {
    // insert code here...
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",f+i);
        mark[ f[i] ]++;
        mylink[ f[i] ] = i;
    }
    for(int i=1;i<=m;i++)
        scanf("%d",d+i);
    int flag=0;
    int mul=0;
    for(int i=1;i<=m;i++)
    {
        if( mark[ d[i] ] == 0 )
        {
            flag=-1;
            break;
        }
        if( mark[ d[i] ]>1)
        {
            mul=1;
        }
    }
    if(flag==-1) printf("Impossible");
    else
        if(mul==1) printf("Ambiguity\n");
    else
    {
        printf("Possible\n");
        for(int i=1;i<=m;i++)
            printf("%d ",mylink[ d[i] ]);
    }
    return 0;
}

C - Day at the Beach

把一个长为N序列,分成n块,使得对于0<=i<n,max(i)<min(i+1)

这样只需要记录从1->i的最大值max(i),和从i->n的最小值min(i)即可。

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;

int g[100100];
int mx[100100],mi[100100];

int main(int argc, const char * argv[]) {
    // insert code here...
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        scanf("%d",g+i);
    mx[1]=g[1];
    for(int i=2;i<=n;i++)
    {
        mx[i]=max(mx[i-1],g[i]);
    }
    mi[n]=g[n];
    for(int i=n-1;i>=0;i--)
    {
        mi[i]=min(mi[i+1],g[i]);
    }
    int ans=0;
    for(int i=1;i<n;i++)
    {
        if( mx[i] <= mi[i+1] ) ans++;
    }
    cout<<ans+1<<endl;
    return 0;
}

D - Spongebob and Squares

看到这题,我真是TM的菜,1个半小时没做出来,其实10分钟就已经想到思路了。先写了程序验证是否可行,然后在推公式的时候又碰到一些问题。

后面想想,如果不会推公式的话用二分暴力完全是可以的。

问题可以变成,给出一个n

从1-n开始枚举。

1:  x=n

2:  3x-1=n

3:  6x-4=n

4:  10x-10

5:  15x-20

6:  21x-35

   ...

n:  (n*(n+1)/2)*x - n*(n+1)*(n-1)/6

然后判断x是否是整数,然后如果枚举过程中,如果x大于i,则结束。稍微分析可以知道(x绝对是小于10^6)

//
//  main.cpp
//  cf332
//
//  Created by 陈加寿 on 15/11/21.
//  Copyright (c) 2015年 陈加寿. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;

long long aa[10001000],bb[10001000];

int main(int argc, const char * argv[]) {
    // insert code here...
        unsigned long long n;
    cin>>n;
    if(n==1)
    {
        printf("1\n1 1\n");
        return 0;
    }
    int ans=0;
    ans=1;
    aa[0]=1;bb[0]=n;
    int flag=0;
    for(unsigned long long i=2;i<=n;i++)
    {
        unsigned long long tmp1,tmp2,tmp3;
        tmp1 = i*(i-1)/2*(i+1)/3;//这个语句还是有问题的感觉。
        tmp2 = i*(i+1)/2;

        tmp3= (n+tmp1)/tmp2;

        if( (n+tmp1)%tmp2==0 )
        {
            if(tmp3 <= i)
            {
                if(i == tmp3)
                {
                    aa[ans] = tmp3;
                    bb[ans] = tmp3;
                    flag=1;
                    ans++;
                }
                break;
            }
            aa[ans]=i; bb[ans]=tmp3; ans++;
        }
        if(tmp3<i) break;
    }
    for(int i=ans-flag-1;i>=0;i--)
    {
        aa[ ans ]=bb[i];
        bb[ ans ]=aa[i];
        ans++;
    }
    cout<<ans<<endl;
    for(int i=0;i<ans;i++)
    {
        cout<<aa[i]<<" "<<bb[i]<<endl;
    }
    return 0;
}
时间: 2024-08-03 03:50:26

Codeforces Round #332 (Div. 2)的相关文章

Codeforces Round #332 (Div. 2) D. Spongebob and Squares(枚举)

http://codeforces.com/problemset/problem/599/D 题意:给出一个数x,问你有多少个n*m的网格中有x个正方形,输出n和m的值. 思路: 易得公式为:$\sum_{i=0}^{n}(n-i)(m-i) $ 化简得:$\left [ n(n+1)-\frac{n(n+1)}{2}\right ]*m+\frac{n(n+1)(n+2)}{6}-\frac{n(n+1)}{2}*n$ 将n作为小的数,枚举n即可. 1 #include<iostream>

Codeforces Round #332 (Div. 二) B. Spongebob and Joke

Description While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. The naughty Sponge browsed through Patrick's personal stuff and found a sequence a1, a2, ..., am of length m, consisting of integers from 1 to n, not

Codeforces Round #332 (Div. 2) B. Spongebob and Joke 模拟

B. Spongebob and Joke While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. The naughty Sponge browsed through Patrick's personal stuff and found a sequence a1, a2, ..., am of length m, consisting of integers from 1

Codeforces Round #332 (Div. 2)A. Patrick and Shopping 水

A. Patrick and Shopping Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a d1 meter long road between his house and the first shop an

Codeforces Round #332 (Div. 2)D. Spongebob and Squares 数学

D. Spongebob and Squares Spongebob is already tired trying to reason his weird actions and calculations, so he simply asked you to find all pairs of n and m, such that there are exactly x distinct squares in the table consisting of n rows and m colum

2017-5-18-Train: Codeforces Round #332 (Div. 2)

A. Patrick and Shopping(模拟题) Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a d1 meter long road between his house and the first sh

Codeforces Round #332 (Div. 2) D. Spongebob and Squares

Spongebob is already tired trying to reason his weird actions and calculations, so he simply asked you to find all pairs of n and m, such that there are exactly x distinct squares in the table consisting of n rows and m columns. For example, in a 3?×

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #633 (Div. 2)

Codeforces Round #633(Div.2) \(A.Filling\ Diamonds\) 答案就是构成的六边形数量+1 //#pragma GCC optimize("O3") //#pragma comment(linker, "/STACK:1024000000,1024000000") #include<bits/stdc++.h> using namespace std; function<void(void)> __