hdu 2651 Spring festival couplets

Spring festival couplets

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 194    Accepted Submission(s): 82

Problem Description

When the spring festival is coming , people always paste spring festival couplets onto the wall.Now dandelion‘s father has bought several spring festival couplets, he wants to know how many pairs of spring festival couplets can been consisted with these spring
festival couplets.As we know ,spring festival couplets are carefully balanced.Such as AABBCCDD can only be matched with AABBCCDD or BBDDEEFF or AABBAABB ...

Input

A number n stands for the number of the spring festival couplets.(2≤n≤110000)

Then n lines ,each line contains a string made by capital letters. Such as AABBCCDD,AABBCCD.The length of the string will not exceed 8.

Output

For every case ,print the number of pairs can be made by these spring festival couplets.

Sample Input

6
ABCCCDA
LLLMNNO
DEZZZBF
AAABCCD
KKKXPPQ
AAA

Sample Output

4

题意比较明确对对联,能配对的就配对问可以配多少对,直接用map映射来做,每次看看之前和当前串一样模式的出现了几次,相加就可以了,输入完就统计完了,不会重复。

然而下午比赛的时候,心情不知道为何会那么烦躁,水题都写不好,还是泡脚回家洗洗睡吧。

#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
#
using namespace std;

char s[10];

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        map<int,int>ss;
        int ans=0;
        for(int i=0;i<n;i++)
        {
            scanf("%s",s);
            int len=strlen(s);
            int p=0;
            int cnt=1;
            for(int j=0;j<len;j++)
            {
                if(j==0) p=1;
                if(s[j-1]==s[j]) p=p*10+cnt;
                else p=p*10+(++cnt);
            }
            if(len<8)
            {
                for(int j=len;j<8;j++)
                {
                     p=p*10+9;
                }
            }

            ans+=ss[p];
            ss[p]++;
        }

        printf("%d\n",ans);
    }

    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-09 14:41:09

hdu 2651 Spring festival couplets的相关文章

hdu 1850 Being a Good Boy in Spring Festival (尼姆博弈)

Being a Good Boy in Spring Festival Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4658    Accepted Submission(s): 2781 Problem Description 一年在外 父母时刻牵挂春节回家 你能做几天好孩子吗寒假里尝试做做下面的事情吧 陪妈妈逛一次菜场悄悄给爸爸买

HDU - 1850 - Being a Good Boy in Spring Festival

先上题目: Being a Good Boy in Spring Festival Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4557    Accepted Submission(s): 2713 Problem Description 一年在外 父母时刻牵挂春节回家 你能做几天好孩子吗寒假里尝试做做下面的事情吧 陪妈妈逛一次菜场

[Nim博弈]hdu 1850 Being a Good Boy in Spring Festival

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1850 Being a Good Boy in Spring Festival Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4053    Accepted Submission(s): 2394 Problem Description

hdu 1850 Being a Good Boy in Spring Festival(Nimm Game)

题意:Nimm Game 思路:Nimm Game #include<iostream> #include<stdio.h> using namespace std; int main(){ int m,a[128],i,sum,ans; while(~scanf("%d",&m)&&m){ sum=0; for(i=0;i<m;++i){ scanf("%d",&a[i]); sum^=a[i]; }

HDU 1850 Being a Good Boy in Spring Festival (Nim游戏变形)

题意:经典Nim游戏博弈,给你n堆牌,每堆a[i]张,每次能从一堆中取出任一张(不能为0),最后不能取者为输 问先手有几种取法保证他最后能获胜. 思路:让Nim_sum=0(a[1]^a[2]----^a[n]=0)时则输,利用这个定理,对于第i堆a[i],除了第i堆,其它的 Nim_sum=k,如果a[i]>k,则先手从第i堆可以取a[i]-k张牌,让a[i]=k,最后a[i]^k==0. #include<cstdio> #include<stdlib.h> #inclu

HDU 1850 Being a Good Boy in Spring Festival 博弈

Being a Good Boy in Spring Festival Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7841    Accepted Submission(s): 4811 Problem Description 一年在外 父母时刻牵挂春节回家 你能做几天好孩子吗寒假里尝试做做下面的事情吧 陪妈妈逛一次菜场悄悄给爸爸买

HDU 1850 —— Being a Good Boy in Spring Festival

Being a Good Boy in Spring Festival Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description 一年在外 父母时刻牵挂春节回家 你能做几天好孩子吗寒假里尝试做做下面的事情吧 陪妈妈逛一次菜场悄悄给爸爸买个小礼物主动地 强烈地 要求洗一次碗某一天早起 给爸妈用心地做回早餐 如果愿意 你还可以和爸妈说咱们玩个小游戏吧

hdu 1850 Being a Good Boy in Spring Festival 博弈论之尼姆博弈,,都被自己蠢哭了!

Being a Good Boy in Spring Festival Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5157    Accepted Submission(s): 3092 Problem Description 一年在外 父母时刻牵挂 春节回家 你能做几天好孩子吗 寒假里尝试做做下面的事情吧 陪妈妈逛一次菜场 悄悄

HDU 1850 Being a Good Boy in Spring Festival (Nim博弈)

#include <iostream> #include <algorithm> #define ss(a) scanf("%d",&a) #define ss64(a) scanf("%I64d",&a) using namespace std; int main() { int a[100],i,n,m,sum,cnt,j; while(~ss(n),n) { cnt=0; for (i=0,sum=0;i<n;i+