zoukankan      html  css  js  c++  java
  • hdu 5229 找规律

    假设选择了字符串a和b:

    假设两人都按照最聪明的策略,那么观察一下可以找出规律:当a和b的字符串长度之和为奇数的时候zcc会败。

    另外当a==b的时候zcc也会败(当时做的时候忘了这个了T^T)

    接下来程序就好写了。总方案数是C(N,2)=N*(N-1)

    判重要用map。

    最后别忘了化简分数。

     1 #include <iostream>
     2 #include<cstring>
     3 #include<map>
     4 #include<vector>
     5 using namespace std;
     6 string s;
     7 int T,N,l;
     8 int ee[20010],oo[20010];
     9 string ss[20010];
    10 
    11 int gcd(int a,int b)
    12 {
    13     if(a<b) swap(a,b);
    14     if(b==0)    return a;
    15     else return (gcd(b,a%b));
    16 }
    17 
    18 int main()
    19 {
    20     cin>>T;
    21     while(T--)
    22     {
    23         memset(ee,0,sizeof(ee));
    24         memset(oo,0,sizeof(oo));
    25         map<string,int>  ht;
    26         cin>>N;
    27         int le=0,lo=0,lx=0;
    28         for(int i=1;i<=N;i++)
    29         {
    30             cin>>s;
    31             ss[i]=s;
    32             l=s.length();
    33             if(ht.count(s))
    34             {
    35                 //cout<<ht[s]<<endl;
    36                 lx+=ht[s];
    37                 ht[s]++;
    38             }
    39             else
    40                 ht.insert(pair<string,int>(s,1));
    41             if(l%2==0)
    42             {
    43                 ee[i]=1;
    44                 le++;
    45             }
    46             else
    47             {
    48                 oo[i]=1;
    49                 lo++;
    50             }
    51         }
    52         //int lx=le*(le-1)/2+lo*(lo-1)/2;
    53         lx+=le*lo;
    54         int ly=N*(N-1)/2;
    55         //cout<<le<<" "<<lo<<" -- "<<lx<<" "<<ly<<endl;
    56         int gg=gcd(lx,ly);
    57         lx=lx/gg;    ly=ly/gg;
    58         cout<<lx<<"/"<<ly<<endl;
    59     }
    60     return 0;
    61 }
    View Code
  • 相关阅读:
    框架
    css样式表。作用是美化HTML网页.
    表单的制作
    表格的制作
    常用标签的制作
    标签的制作
    poj2104(K-th Number)
    Codeforces Round #359 (Div. 2) D. Kay and Snowflake
    Codeforces Round #359 (Div. 2) C. Robbers' watch
    HDU3308(LCIS) 线段树好题
  • 原文地址:https://www.cnblogs.com/pdev/p/4511580.html
Copyright © 2011-2022 走看看