BC#41 hdu 5228 5229

ZCC loves straight flush

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 134    Accepted Submission(s): 59


Problem Description
After losing all his chips when playing Texas Hold'em with Fsygd on the way to ZJOI2015, ZCC has just learned a black technology. Now ZCC is able to change all cards as he wants during the game. ZCC wants to get a Straight Flush by changing as few cards as possible. 

We call a five-card hand a Straight Flush when all five cards are consecutive and of the same suit. You are given a five-card hand. Please tell ZCC how many cards must be changed so as to get a Straight Flush.
  
Cards are represented by a letter('A', 'B', 'C', 'D') which denotes the suit and a number('1', '2',  , '13') which denotes the rank.
  
Note that number '1' represents ace which is the largest actually. "1 2 3 4 5" and "10 11 12 13 1" are both considered to be consecutive while "11 12 13 1 2" is not.
 

Input
First line contains a single integer  T(T=1000)  which denotes the number of test cases.
For each test case, there are five short strings which denote the cards in a single line. It's guaranteed that all five cards are different.
 

Output
For each test case, output a single line which is the answer.
 

Sample Input
  
  
3 A1 A2 A3 A4 A5 A1 A2 A3 A4 C5 A9 A10 C11 C12 C13
 

Sample Output
  
  
0 1 2
 


给出牌的花色和点数 现在要使得这5张牌变为同花顺 求要替换的牌的最少张数

枚举牌的点数 花色的情况就可以了

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <string>
#include <vector>
#include <queue>

#define MEM(a,x) memset(a,x,sizeof a)
#define eps 1e-8
#define MOD 10009
#define MAXN 10010
#define MAXM 100010
#define INF 99999999
#define ll __int64
#define bug cout<<"here"<<endl
#define fread freopen("ceshi.txt","r",stdin)
#define fwrite freopen("out.txt","w",stdout)

using namespace std;

int Read()
{
    char c = getchar();
    while (c < '0' || c > '9') c = getchar();
    int x = 0;
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x;
}

void Print(int a)
{
     if(a>9)
         Print(a/10);
     putchar(a%10+'0');
}

int num[4];
int order[5],color[5];
char ch[5][5];
int vis[14];

struct node
{
    int id,num,color[6];
};
node no[14];

int main()
{
//    fread;
    int tc;
    scanf("%d",&tc);
    while(tc--)
    {
        MEM(num,0); MEM(vis,0);
        for(int i=0;i<5;i++)
            scanf("%s",ch[i]);

        for(int i=1;i<=13;i++)
        {
            no[i].id=i,no[i].num=0;
            for(int j=0;j<4;j++)
                no[i].color[j]=0;
        }
        for(int i=0;i<5;i++)
        {
//            num[ch[i][0]-'A']++;
            color[i]=ch[i][0]-'A';
            order[i]=ch[i][1]-'0';
            if(ch[i][2]!='\0')
            {
                order[i]*=10;
                order[i]+=ch[i][2]-'0';
            }
//            cout<<order[i]<<endl;
            no[order[i]].num++;
            no[order[i]].color[ch[i][0]-'A']=1;
        }
//        for(int i=1;i<=13;i++)
//        {
//            for(int j=0;j<4;j++)
//                cout<<i<<" "<<j<<" "<<no[i].color[j]<<endl;
//        }
        int res=-1;
        for(int i=1;i<10;i++)
        {
            int cnt[4];
            MEM(cnt,0);
            for(int j=0;j<5;j++)
            {
                if(no[i+j].num)
                {
                    for(int k=0;k<4;k++)
                    {
                        if(no[i+j].color[k])
                            cnt[k]++;
                    }
                }
            }

            for(int j=0;j<4;j++)
            {
//                cout<<j<<" "<<cnt[j]<<endl;
                 res=max(res,cnt[j]);
            }
        }
        int cnt[4];
        MEM(cnt,0);
        for(int i=0;i<4;i++)
        {

            if(no[10+i].num)
            {
                for(int k=0;k<4;k++)
                {
                    if(no[10+i].color[k])
                            cnt[k]++;
                }
            }
        }
        if(no[1].num)
        {
            for(int k=0;k<4;k++)
                if(no[1].color[k])
                    cnt[k]++;
        }
        for(int j=0;j<4;j++)
        {
//                cout<<j<<" "<<cnt[j]<<endl;
            res=max(res,cnt[j]);
        }
        printf("%d\n",5-res);
    }
    return 0;
}


ZCC loves strings

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/131072 K (Java/Others)
Total Submission(s): 126    Accepted Submission(s): 52


Problem Description
ZCC has got N strings. He is now playing a game with Miss G.. ZCC will pick up two strings among those N strings randomly(A string can't be chosen twice). Each string has the same probability to be chosen. Then ZCC and Miss G. play in turns. Miss G. always plays first. In each turn, the player can choose operation A or B.
  
Operation A: choose a non-empty string between two strings, and delete a single letter at the end of the string.
    
Operation B: When two strings are the same and not empty, empty both two strings.
  
The player who can't choose a valid operation loses the game.
  
ZCC wants to know what the probability of losing the game(i.e. Miss G. wins the game) is.
 

Input
The first line contains an integer  T(T5)  which denotes the number of test cases.
  
For each test case, there is an integer  N(2N20000)  in the first line. In the next N lines, there is a single string which only contains lowercase letters. It's guaranteed that the total length of strings will not exceed 200000.
 

Output
For each test case, output an irreducible fraction "p/q" which is the answer. If the answer equals to 1, output "1/1" while output "0/1" when the answer is 0.
 

Sample Input
  
  
1 3 xllendone xllendthree xllendfour
 

Sample Output
  
  
2/3
 


题意不再赘述

zcc不会让两个字符串出现执行操作B的情况 除非两个字符串一开始就是相同的

所以对于一般的情况 两个字符串中的字符肯定是一个一个的取出的

所以两个字符串中字符长度的和为奇数  需要一个长度为偶数一个长度为奇数的字符串进行搭配

另外还有两个字符串是一样的 如果一个字符串的个数是k  则可以随意取出两个 就是k选2的组合数

为 k*(k-1)/2

所以情况的数量为n*(n-1)/2

注意分数的化简 

(当时数组开小了。。。。然后没过大数据)

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <string>
#include <vector>
#include <queue>
#include <map>

#define MEM(a,x) memset(a,x,sizeof a)
#define eps 1e-8
#define MOD 10009
#define MAXN 2000010
#define MAXM 100010
#define INF 99999999
#define ll __int64
#define bug cout<<"here"<<endl
#define fread freopen("ceshi.txt","r",stdin)
#define fwrite freopen("out.txt","w",stdout)

using namespace std;

int Read()
{
    char c = getchar();
    while (c < '0' || c > '9') c = getchar();
    int x = 0;
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x;
}

void Print(int a)
{
     if(a>9)
         Print(a/10);
     putchar(a%10+'0');
}

char ch[MAXN];
map<string,int> mp;
map<string,int>:: iterator it;
int gcd(int a,int b)
{
    if(b==0) return a;
    return gcd(b,a%b);
}

int main()
{
//    fread;
    int tc;
    scanf("%d",&tc);
    while(tc--)
    {
        mp.clear();
        int n;
        scanf("%d",&n);
        int odd=0,even=0;
        for(int i=0;i<n;i++)
        {
            scanf("%s",ch);
            mp[(string)ch]++;
            int len=strlen(ch);
            if(len%2)
                odd++;
            else even++;
        }
        int num1,num2;
        num1=odd*even;
        for(it=mp.begin();it!=mp.end();it++)
        {
            num1+=(it->second)*(it->second-1)/2;
        }
        num2=n*(n-1)/2;
        int g=gcd(num1,num2);
        num1/=g;
        num2/=g;
        printf("%d/%d\n",num1,num2);
    }
    return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值