• ccpc2017杭州


    solve   A B C D E F G H I J K L      
    5/12     ac ac ac ac           ac try        

    A - Super-palindrome

    题意 : 一个字符串,每个子串都要是回文的,问你最少翻几个。

    如果每一个字符串都是回文串,那么最终奇数位等于奇数位,偶数位等于偶数位,

    #include<bits/stdc++.h>
    using namespace std;
    const int N=1e2+5;
    char s[N];
    int a[30],b[30];
    int main(){
        int t;
        scanf("%d",&t);
        while(t--){
        memset(a,0,sizeof a);
        memset(b,0,sizeof b);
            scanf("%s",s);
        int len=strlen(s);
        for(int i=0;i<len;i++){
        if(i&1)a[s[i]-'a']++;
        else b[s[i]-'a']++;
        }
        sort(a,a+26,greater<int>() );
        sort(b,b+26,greater<int>() );
        int ans=len-a[0]-b[0];
        printf("%d
    ",ans);
        }
    
        // system("pause");
        return 0;
    }
    View Code

     D - Master of Random

    题意:一颗任意的树,求期望排列,逆元+思维。

    总情况肯定是 n!个,对于每一个节点,被作为树根的构造方案是(n-1)/k,累加即可。

    #include<bits/stdc++.h>
    using namespace std;
    const int N=1e5+5;
    typedef long long ll;
    const ll MOD=998244353;
    ll a[N];
    ll quickPower(ll a, ll b,ll m) {   //计算a的b次方
        ll ans = 1;
        ll base = a;
        while (b) {
            if (b & 1) {
                ans *= base;
                ans %= m;
            }
            base *= base;
            base %= m;
            b >>= 1;   //注意是b>>=1 not b>>1
        }
        return ans;
    }
    int main(){
        int t,n;
        scanf("%d",&t);
        while(t--){
        scanf("%d",&n);
        for(int i=0;i<n;i++)scanf("%lld",&a[i]);
        ll nv=1;
        for(int i=1;i<n;i++)nv=(nv*i)%MOD;
        ll t=nv,sum=nv*a[0]%MOD;
        for(int i=1;i<n;i++){
        t=(t+nv*quickPower(i*1ll,MOD-2,MOD)%MOD)%MOD;
        sum=(sum+t*a[i])%MOD;
        }
        nv=(nv*n)%MOD;
        ll ans=(sum*quickPower(nv*1ll,MOD-2,MOD)%MOD)%MOD;
        printf("%lld
    ",ans);
        }
        // system("pause");
        return 0;
    }
    View Code

    C - Hakase and Nano

     HDU - 6266 

    可以这样考虑:

    先手时:n是三的倍数3而且全是1,那么没办法,只能输了。

    后手时:n是三的倍数加一,而且全是1时,没办法,必输。

        n是三的倍数加一,而且有一个不是1时,另一个人取走一堆,转化上面情况。

        n是三的倍数,有一个不是1,把那堆取到剩一个1,转化上面情况。

      

    #include<bits/stdc++.h>
    using namespace std;
    #define pb push_back
    #define fi first
    #define se second
    typedef long long ll;
    typedef double db;
    const double eps=1e-8;
    const int N=1e6+6;
    int main(){
      int n,t,d;
      scanf("%d",&t);
      while(t--){
      scanf("%d %d",&n,&d);
      int a,cnt=0;
      for(int i=1;i<=n;i++){
        scanf("%d",&a);
        if(a==1)cnt++;
      }
      if(d==1){
      if(n%3==0&&cnt==n)puts("No");
      else puts("Yes");
      }
      else if(d==2){
        if(n%3==1&&cnt==n)puts("No");
        else if(n%3==1&&cnt==n-1)puts("No");
        else if(n%3==0&&cnt==n-1)puts("No");
        else puts("Yes");    
      }
      }
      // system("pause");
      return 0;
    }
    View Code
    想的太多,做的太少;
  • 相关阅读:
    [MST] Test mobx-state-tree Models by Recording Snapshots or Patches
    [MST] Attach Behavior to mobx-state-tree Models Using Actions
    [MST] Describe Your Application Domain Using mobx-state-tree(MST) Models
    [Angular] Configure an Angular App at Compile Time with the Angular CLI
    [Angular] Configure an Angular App at Runtime
    [Test] Easy automated testing in NodeJS with TestCafe
    [React] Optimistic UI update in React using setState()
    [Javascript] Required function arguments in Javascript
    [Transducer] Lazyness in Transduer
    [Transducer] Create a Sequence Helper to Transduce Without Changing Collection Types
  • 原文地址:https://www.cnblogs.com/littlerita/p/12663912.html
Copyright © 2020-2023  润新知