::CF目录::

................................目录..................................

Round #167 (Div. 2)

A.Dima and Friends           类型: 模拟

题意:有n个朋友每个人出1~5中的一个数,自己可以出1~5中的任意一个数,把所有数的和加起来得到的m,从自己开始一次倒数

        最后一个人扫地,问自己有多少种出法,自己不用扫地。

分析:直接模拟

View Code
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
#define clr(x) memset(x,0,sizeof(x))
const double eps = 1e-8;

int a[101];
int b[6];
int main()
{
    int i, j, k;
    int t, n, m;
    while (scanf("%d",&n)!=EOF)
    {
        clr(b);
        int tot = 0;
        int rr=  0;
        for (i=0; i<n; i++)
        {
            int p;
            scanf("%d",&p);
            rr += p;
        }
        for (j=1; j<=5; j++)
            if ((j+rr-1)%(n+1)!=0)
                tot++;
        printf("%d\n",tot);
    }

    return 0;
}

 

B.Dima and Sequence      类型:  模拟

题意:

分析:

View Code
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
#define clr(x) memset(x,0,sizeof(x))
const double eps = 1e-8;

long long a[100005];
long long f[11];
void init()
{
    f[1] = 1; f[2] = 1; f[3] = 2; f[4] = 1; f[5] = 2;
    f[6] = 2; f[7] = 3; f[8] = 1; f[9] = 2; f[10] = 2;
}
int main()
{
    int i, j, k;
    int t, n, m;
    long long res;
    init();
    while (scanf("%d",&n)!=EOF)
    {
        res = 0;
        for (i=0; i<n; i++)
        {
            scanf("%I64d",&a[i]);
            long long tmp = 0;
            while (a[i]>10)
            {
                if (a[i]&1){
                    a[i] = (a[i]-1)/2;
                    tmp += 1;
                }
                else a[i] /= 2;
            }
            a[i] = f[a[i]]+tmp;
        }
        sort(a,a+n);
        long long tot = 0;
        for (i=0; i<n; i++)
        {
            tot++;
            if (i==n-1 || a[i]!=a[i+1])
            {
                res += (tot-1)*tot/2;
                tot = 0;
            }
        }
        printf("%I64d\n",res);
    }

    return 0;
}

 

C.Dima and Staircase       类型:  模拟

题意:

分析:

View Code
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
#define clr(x) memset(x,0,sizeof(x))
const double eps = 1e-8;

long long a[100005];
int main()
{
    int i, j, k;
    int t, n, m;
    long long w, h;
    while (scanf("%d",&n)!=EOF)
    {
        for (i=1; i<=n; i++)
            scanf("%I64d",&a[i]);
        scanf("%d",&m);
        long long h1,h2;
        while (m--)
        {
            scanf("%I64d %I64d",&w,&h);
            if (w > n)
                w = n;
            h1 = a[w];
            h2 = a[1];
            printf("%I64d\n",max(h1,h2));
            a[w] = a[1] = max(h1,h2)+h;
        }
    }
    return 0;
}

 

D.Dima and Two Sequences   类型:组合数

题意:

分析:

View Code
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 200005;
struct node
{
    long long x, y;
}q[maxn];

int tp, n;
long long d[maxn];
long long m;
long long cal()
{
    long long r = 1;
    long long i,tot = 0, s = 0, num = 0;
    d[tp] = -1;
    for (i=0; i<tp; i++){
        s++;
        num++;
        if (d[i] != d[i+1]){
            if (num == 2)
                r = (((tot+1)*(tot+2)/2)%m*r)%m;
            else
                r = (r*(tot+1))%m;
            num = 0;
            tot = s;
        }
    }
    return r;
}

bool cmp(node a,node b)
{
    if (a.x != b.x)
        return a.x<b.x;
    return a.y<b.y;
}
int main()
{
   // freopen("in.in","r",stdin);
    long long i;
    long long r, res;
    while (scanf("%d",&n)!=EOF)
    {
        for (i=0; i<n; i++){
            scanf("%I64d",&q[i].x);
            q[i].y = i+1;
        }
        for (i=0; i<n; i++){
            scanf("%I64d",&q[i+n].x);
            q[i+n].y = i+1;
        }
        scanf("%I64d",&m);
        sort(q,q+2*n,cmp);
        q[2*n].x = q[2*n].y = -1;
        tp = 0;
        res = 1;
        for (i=0; i<2*n; i++){
            d[tp++] = q[i].y;
            if (q[i].x != q[i+1].x){
                r = cal();
                res = (res*r)%m;
                tp = 0;
            }
        }
        printf("%I64d\n",res);
    }
    return 0;
}

 

posted @ 2013-02-12 12:03  'wind  阅读(267)  评论(0编辑  收藏  举报