zoukankan      html  css  js  c++  java
  • codeforces #309 DIV2

    这场并没有做,做的赛后的,太晚了时间,中午做了两题,稍微贴一下,剩余的题目本周争取补完

    A题:

    链接:http://codeforces.com/contest/554/problem/A

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<string>
     5 #include<cmath>
     6 #include<vector>
     7 #include<stack>
     8 #include<algorithm>
     9 using namespace std;
    10 string s;
    11 int main()
    12 {
    13     while(cin>>s)
    14     {
    15         int n=s.length();
    16             cout<<n*25+26<<endl;
    17     }
    18     return 0;
    19 }
    View Code

    B题:

    链接:http://codeforces.com/contest/554/problem/B

    其实就是判相等的行数

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<string>
     5 #include<cmath>
     6 #include<vector>
     7 #include<stack>
     8 #include<queue>
     9 #include<algorithm>
    10 using namespace std;
    11 const int maxn=101;
    12 string s[maxn];
    13 int main()
    14 {
    15     int n;
    16     while(cin>>n)
    17     {
    18         for(int i=0;i<n;i++)
    19             cin>>s[i];
    20         int mx=0;
    21         int cnt;
    22         for(int i=0;i<n;i++)
    23         {
    24             cnt=0;
    25             for(int j=0;j<n;j++)  //找到一样的行就行了
    26                 if(s[i]==s[j])
    27                 cnt++;
    28                 if(cnt>mx)
    29                 mx=cnt;
    30         }
    31         cout<<mx<<endl;
    32     }
    33     return 0;
    34 }
    View Code


    剩余的题目本周末一定争取补完

    继续补题中,今天补得是C题,这题非常有意思,经典的组合计数,很有数学的味道,开始完全没思路,后来跟王远立和李大神讨论,王远立给我了思路,启发了我,之后晚上又参看了一下题解,终于A了,还学会了求组合数一个比较好的办法,不用阶乘,用公式:,非常好

    题目链接:http://codeforces.com/contest/554/problem/C

    贴一下神牛的思路,非常清晰易懂:http://blog.csdn.net/libin56842/article/details/46650209

    非常好的插空法

    下面是我的代码:

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<string>
     5 #include<cmath>
     6 #include<vector>
     7 #include<algorithm>
     8 #include<stack>
     9 #define mod 1000000007
    10 using namespace std;
    11 const int maxn=1000+10;
    12 int a[maxn];
    13 long long  dp[maxn][maxn];
    14 void pre()  //很好的求组合数的方法
    15 {
    16     dp[0][0]=1;
    17     for(int i=1;i<maxn;i++)
    18     {
    19         dp[i][i]=1;
    20         dp[i][0]=1;
    21         for(int j=1;j<i;j++)
    22             dp[i][j]=(dp[i-1][j]+dp[i-1][j-1])%mod;
    23     }
    24 }
    25 int main()
    26 {
    27     int k;
    28     pre();
    29     while(cin>>k)
    30     {
    31         int total=0;
    32         for(int i=0;i<k;i++)
    33         {
    34             cin>>a[i];
    35             total+=a[i];
    36         }
    37         long long res=1;
    38         for(int i=k-1;i>0;i--)
    39         {
    40             res*=dp[total-1][a[i]-1];
    41             res%=mod;
    42             total-=a[i];
    43         }
    44         cout<<res<<endl;
    45     }
    46     return 0;
    47 }
    View Code

     D题明天在补,这次争取尝试尝试D

    D题:

    链接:http://codeforces.com/problemset/problem/553/B

    先来说说题意吧,就是有一串数p[n],然后1到n分别映射到p[1]到p[n],比如:p = [4, 1, 6, 2, 5, 3]得到(142)(36)(5) 1被4代表, 4被2代表, 2被1代表, 3和6互换,  5保持原来位置不变。然后进行循环左移,将每个周期排序,在将周期之间的第一个元素排序排序,得到如下:(421)(5)(63)。然后求最终变化之后跟原来序列相同的,并且第k种排列

  • 相关阅读:
    用Javascript进行简单的Table点击排序.
    asp也来玩三层?
    用在JavaScript的RequestHelper
    一个JavaScript方法的演变
    自己动手,实现jQuery中的ImageCopper.
    notes on relations
    mutex and condition variable
    virtual destructor
    virtual inheritance
    一道概率题
  • 原文地址:https://www.cnblogs.com/wolf940509/p/4601282.html
Copyright © 2011-2022 走看看