• Codeforces Round #253 (Div. 1)-A,B


    A题:

    由题意可知,最多翻10次就能够(事实上8次就够了)。那么我们就用状态压缩表示状态。

    对于某种状态,假设某一位为0,那么代表这一位不翻,否则代表这一位翻。

    对于某一种翻的状态:

    假设牌中有G3,那么就把G和3进行连边。

    其它的连边类似。不要重边。

    对于随意一条边的两个端点。分三种情况讨论:

    1。两个端点都翻了,那么非常明显,这张牌被表示出来了。

    2,两个端点中仅仅有一个端点被翻。那么这个相应的num加1.

    3,两个端点都没有被翻,计数器tt加1。

    对于随意一种状态:

    1,假设计数器tt大于1,那么肯定不能推断出全部的牌。

    2。假设随意一个端点的num数大于1。那么也肯定不能推断出全部的牌。

    3。否则的话,这样的状态能够表示出全部的牌。

    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    #include<iostream>
    #include<vector>
    using namespace std;
    #define LL __int64
    #define maxn 2201
    int num[20];
    int pan[220];
    int name[22001];
    vector<int>vec;
    int map[110][110];
    void dos(int x)
    {
        while(x)
        {
            cout<<x%2;
            x=x/2;
        }
        cout<<endl;
    }
    int main()
    {
        int n,l,r,x,y;
        char str[1010];
        pan['R']=6;
        pan['G']=7;
        pan['B']=8;
        pan['Y']=9;
        pan['W']=5;
        while(~scanf("%d",&n))
        {
            memset(num,0,sizeof(num));
            memset(name,0,sizeof(name));
            memset(map,0,sizeof(map));
            l=r=0;
            for(int i=1; i<=n; i++)
            {
                scanf("%s",str);
                x=pan[str[0]];
                y=str[1]-'1';
                map[x][y]++;
                map[y][x]++;
            }
            int st=0;
            int minn =10;
            for(int st=0; st<(1<<10); st++)
            {
                int ss=0;
                for(int j=0; j<10; j++)
                {
                    if(st&(1<<j))ss++;
                }
                if(ss>=minn)continue;
                int leap=0;
                int t=0;
                memset(num,0,sizeof(num));
                for(int j=5; j<10; j++)
                {
                    for(int i=0; i<5; i++)
                    {
                        if(map[i][j])
                        {
                            if((st&(1<<i))&&(st&(1<<j)))continue;
                            if((st&(1<<i))||(st&(1<<j)))
                            {
                                if(st&(1<<i))
                                {
                                    if(!num[i])
                                    {
                                        num[i]++;
                                        continue;
                                    }
                                }
                                if((st&(1<<j)))
                                {
                                    if(!num[j])
                                    {
                                        num[j]++;
                                        continue;
                                    }
                                }
                            }
                            else
                            {
                                if(t==0)
                                {
                                    t++;
                                    continue;
                                }
                            }
                            leap++;
                        }
                    }
                }
                if(!leap)
                {
                    minn=min(minn,ss);
                 //   cout<<" "<<ss<<" ";
                  //  dos(st);
                }
    
            }
            cout<<minn<<endl;
        }
        return 0;
    }
    B题:

    对于当前选择的状态,

    p0表示0个人告诉答案的概率。

    p1表示1个人告诉答案的概率。

    对于即将面对的一个人:

    a表示0个人告诉答案的概率。

    b表示1个人告诉答案的概率。

    假设接纳这个人之后,p1的值变小了。那么就不应该接纳下去。

    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    #include<iostream>
    #include<vector>
    using namespace std;
    #define LL __int64
    #define maxn 2201
    double num[maxn];
    int main()
    {
        int n;
        double x;
        while(~scanf("%d",&n))
        {
            for(int i=1;i<=n;i++)
            {
                scanf("%lf",&num[i]);
            }
            sort(num+1,num+n+1);
            double ans=0;
            double a=1;
            double c,d;
            double b=0;
            for(int i=n;i>=1;i--)
            {
                c=a;
                d=b;
                b=b+a*num[i]-b*num[i];
                a=a-a*num[i];
                if(b<d)
                {
                    b=d;
                    break;
                }
            }
            printf("%.10lf
    ",b);
        }
        return 0;
    }
    












  • 相关阅读:
    Git fetch和git pull的区别
    git revert和git reset的区别
    JSF 与 HTML 标签的联系
    3. Decorator
    2. Observer
    1. Strategy
    继承构造函数的执行顺序
    模板特化
    8.1.2 Template instantiation (Accelerated C++)
    std::cin
  • 原文地址:https://www.cnblogs.com/yutingliuyl/p/6890348.html
Copyright © 2020-2023  润新知