HDU5229-ZCC loves strings

本文介绍了一个关于字符串的游戏,玩家通过删除字符串中的字符进行博弈,分析了先手玩家获胜的概率,并给出了具体的算法实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ZCC loves strings

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

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
 
Source
 
Recommend
hujie


题意:有N个字符串,从这N个串中等概率随机选两个字符串(不可以是同一个)。然后两个人轮流操作,有两种操作:如果两个字符串相同,可以删除这两个字符串;不相同则选择一个字符串,删掉最后一个字符。第一个不能操作的人输。问先手获胜的概率

解题思路:对于先手来说,如果两个串相同,则先手赢。如果两个串的总共有奇数个字符则先手赢,否则先手输。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>

using namespace std;

string s[20009];

int gcd(int x,int y)
{
    if(x>y) return gcd(y,x);
    while(y%x)
    {
        int t=x;
        x=y%x;
        y=t;
    }
    return x;
}

int main()
{
    int t,n,a,b;
    scanf("%d",&t);
    while(t--)
    {
        a=b=0;
        scanf("%d",&n);
        for(int i=0;i<n;i++)
        {
            cin>>s[i];
            if(s[i].length()%2) a++;
            else b++;
        }
        sort(s,s+n);
        int sum=n*(n-1)/2;
        int sum1=a*b;
        int k=1;
        for(int i=1;i<n;i++)
        {
            if(s[i]==s[i-1]) k++;
            else
            {
                sum1+=(k-1)*k/2;
                k=1;
            }
        }
        sum1+=(k-1)*k/2;
        printf("%d/%d\n",sum1/gcd(sum1,sum),sum/gcd(sum,sum1));
    }
    return 0;
}

资源下载链接为: https://pan.quark.cn/s/22ca96b7bd39 在当今的软件开发领域,自动化构建与发布是提升开发效率和项目质量的关键环节。Jenkins Pipeline作为一种强大的自动化工具,能够有效助力Java项目的快速构建、测试及部署。本文将详细介绍如何利用Jenkins Pipeline实现Java项目的自动化构建与发布。 Jenkins Pipeline简介 Jenkins Pipeline是运行在Jenkins上的一套工作流框架,它将原本分散在单个或多个节点上独立运行的任务串联起来,实现复杂流程的编排与可视化。它是Jenkins 2.X的核心特性之一,推动了Jenkins从持续集成(CI)向持续交付(CD)及DevOps的转变。 创建Pipeline项目 要使用Jenkins Pipeline自动化构建发布Java项目,首先需要创建Pipeline项目。具体步骤如下: 登录Jenkins,点击“新建项”,选择“Pipeline”。 输入项目名称和描述,点击“确定”。 在Pipeline脚本中定义项目字典、发版脚本和预发布脚本。 编写Pipeline脚本 Pipeline脚本是Jenkins Pipeline的核心,用于定义自动化构建和发布的流程。以下是一个简单的Pipeline脚本示例: 在上述脚本中,定义了四个阶段:Checkout、Build、Push package和Deploy/Rollback。每个阶段都可以根据实际需求进行配置和调整。 通过Jenkins Pipeline自动化构建发布Java项目,可以显著提升开发效率和项目质量。借助Pipeline,我们能够轻松实现自动化构建、测试和部署,从而提高项目的整体质量和可靠性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值