2019省赛训练-N+6

http://acm.sdibt.edu.cn/vjudge/contest/view.action?cid=2234#overview

A - Wrestling Match

Sample Input

5 4 0 0
1 3
1 4
3 5
4 5
5 4 1 0
1 3
1 4
3 5
4 5
2 
 
Sample Output

NO
YES 

题意:多组样例,第一行给出4个数n(总人数,标号1~n),m(接下来m组数据,一组两个数),x(good player),y(bad player).如果x,y不为0,后面会给出x+y个数据,x个数表示这些编号的一定是good player,y个数表示这些编号的一定是bad player.要求那m组数据的两个数一定不在同一个分类中。问能确定这些人的分组吗。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <set>
#define MAX 0x3f3f3f3f
#define fori(a,b) for(int i=a;i<=b;i++)
#define forj(a,b) for(int j=a;j<=b;j++)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const int M=1e4+10;
const int mod=1e9+7;
int f[M],a[M];
int xx,yy;
int g[M],b[M];
vector<int>v[M];
int main()
{
    //freopen("//home//acm//桌面//in","r",stdin);
    int n,m,x,y;
    while(cin >> n >> m >> x >> y){
        mem(a,0);
        int flag=0;
        for(int i=1;i<=n;i++){
            f[i]=i;
            v[i].clear();
        }
        for(int i=1;i<=m;i++){
            scanf("%d%d",&xx,&yy);
            v[xx].push_back(yy);
        }
        for(int i=1;i<=x;i++){
            scanf("%d",&g[i]);
        }
        for(int i=1;i<=y;i++){
            scanf("%d",&b[i]);
        }
        for(int i=1;i<=x;i++){
            if(f[g[i]]!=-1111){
                f[g[i]]=1111;
                a[g[i]]=1;
                for(int j=0;j<v[g[i]].size();j++){
                    if(f[v[g[i]][j]]!=1111)
                        f[v[g[i]][j]]=-1111,a[v[g[i]][j]]=1;
                    else {
                        flag=1;
                        break;
                    }
                }
            }
            else {
                flag=1;
                break;
            }
        }
        if(!flag){
            for(int i=1;i<=y;i++){
            if(f[b[i]]!=1111){
                f[b[i]]=-1111;
                a[b[i]]=1;
                for(int j=0;j<v[b[i]].size();j++){
                    if(f[v[b[i]][j]]!=-1111)
                        f[v[b[i]][j]]=1111,a[v[b[i]][j]]=1;
                    else {
                        flag=1;
                        break;
                    }
                }
            }
            else {
                flag=1;
                break;
            }
            }
        }
        if(!flag){
            for(int i=1;i<=n;i++){
                if(!a[i]){
                    f[i]=1111;
                    a[i]=1;
                    int len=v[i].size();
                    if(len==0){
                        flag=1;
                        break;
                    }
                    for(int j=0;j<len;j++){
                        if(f[v[i][j]]!=1111)
                            f[v[i][j]]=-1111,a[v[i][j]]=1;
                        else {
                            flag=1;
                            break;
                        }
                    }
                }
                else {
                    int len=v[i].size();
                    for(int j=0;j<len;j++){
                        if(f[v[i][j]]!=f[i])
                            f[v[i][j]]=-f[i],a[v[i][j]]=1;
                        else {
                            flag=1;
                            break;
                        }
                    }
                }
            }

        }
        if(!flag)
            printf("YES\n");
        else
            printf("NO\n");

    }
    return 0;
}

H - To begin or not to begin

OutputFor each case, output: 
1, if the player who starts drawing has an advantage 
2, if the player who starts drawing has a disadvantage 
0, if Alice's and Bob's chances are equal, no matter who starts drawing 
on a single line. 
 
 

Sample Input
1
2 
Sample Output
0
1 

题意:一个盒子中一定有1个红球,现在给出n个黑球,有两个人进行摸球比赛,谁先摸到红球谁就赢得比赛,如果对先手有利输出1,对先手无利输出2,如果机会均等就输出0.

思路:当n=1时,代表有1黑1红,先手可以摸一次,先手赢概率:1/2,后手赢概率1/2,输出0.

           当n=2时,代表有2黑1红,先手可以摸两次,先手赢概率:1/3+2/3*1/2=2/3,后手赢概率1/3,输出1.

           当n=3时,代表有3黑1红,先手可以摸两次,先手赢概率:1/4+3/4*2/3*1/2=1/2,后手赢概率1/2,输出0.

           当n=4时,代表有4黑1红,先手可以摸三次,先手赢概率:1/5+4/5*3/4*1/3+4/5*3/4*2/3*1/2=3/5,后手赢概率2/5,输出1.

  所以当n是偶数是输出1,当n是奇数时输出0.

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <set>
#define MAX 0x3f3f3f3f
#define fori(a,b) for(int i=a;i<=b;i++)
#define forj(a,b) for(int j=a;j<=b;j++)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const int M=1e5+10;
const int mod=1e9+7;
int main()
{
    //freopen("//home//acm//桌面//in","r",stdin);
    int n;
    while(cin >>n){
        if((n+1)%2==1)
            cout << "1" <<endl;
        else
            cout <<"0" <<endl;
    }
    return 0;
}

I - Convex

Sample Input

4 1
90 90 90 90
6 1
60 60 60 60 60 60 
 
Sample Output

2.000
2.598 

题意:给出n个角的形状,边长,中心在原点上,问面积是多少。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <set>
#define MAX 0x3f3f3f3f
#define fori(a,b) for(int i=a;i<=b;i++)
#define forj(a,b) for(int j=a;j<=b;j++)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const int M=1e5+10;
const int mod=1e9+7;
double a[M];
int main()
{
    //freopen("//home//acm//桌面//in","r",stdin);
    int n,m;
    double ans;
    while(cin >> n >> m){
            ans=0;
        for(int i=1;i<=n;i++){
            cin >> a[i];
            ans+=0.5*m*m*sin(a[i]*PI/180.0);
        }
        printf("%.3lf\n",ans);
    }
    return 0;
}

 

J - Find Small A

Sample Input

3
97 24929 100 
 
Sample Output

3 

题意:给出n个数,每个数32位,问这些数里面有多少个‘a'(97,2进制是8位)。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <set>
#define MAX 0x3f3f3f3f
#define fori(a,b) for(int i=a;i<=b;i++)
#define forj(a,b) for(int j=a;j<=b;j++)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const int M=1e5+10;
const int mod=1e9+7;
string s,t="10000110";
int main()
{
    //freopen("//home//acm//桌面//in","r",stdin);
    ll n,l=0,m,ans=0;
    cin>> n;
    for(int i=1;i<=n;i++){
        s.clear();
        scanf("%lld",&m);
        while(m){
            s+=m%2+'0';
            m/=2;
            if(s.size()==8){
                if(s==t)
                    ans++;
                s.clear();
            }
        }
        while(s.size()!=8)
            s+='0';
        if(s==t)
            ans++;

        //cout << s <<endl;

    }
    printf("%lld\n",ans);
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值