zoukankan      html  css  js  c++  java
  • cf-gym100500-b Conference Room

    题意:给你4个1000长度的数组,每个数组可以转动(比如a[1] = a[3],a[2] = a[1] ,a[3] = a[2]) ,问能否有种情况使得任意的i(1-n)a[i]+b[i]+c[i]+d[i] = sum,sum是自己给的一个值。
    思路:

    1. 能想通sum是求出来的,及所有的4个数组的累加和被n除。
    2. 那么我们把一个数组转动1000次每次每一位和sum做差压入set里,只要剩下三个数组hash值相加可以等于set里一个数则输出Yes
      另一种解法:https://www.cnblogs.com/nervendnig/p/11637240.html
      代码:
    #include <bits/stdc++.h>
    using namespace std;
    #define ull long long
    #define forn(i,n) for(int i = 0;i<n;++i)
    #define for1(i,n) for(int i=1;i<=n;++i)
    #define IO ios::sync_with_stdio(false);cin.tie(0)
    const int maxn = 1e3+5;
    const int seed = 1e9+123;
    int a[4][maxn];
    ull b[2][maxn];
    
    int main(){
        IO;
        int t;cin>>t;
        for1(casee,t){
            int n;cin>>n;
            long long sum = 0;
            forn(i,4){
                forn(j,n){
                    cin>>a[i][j];
                    sum+=a[i][j];
                }
            }
            bool win = 0;
            if(sum%n==0){
                sum/=n;
                set<ull>s;
                forn(i,n){
                    ull h = 0;
                    forn(j,n)  h = h*seed+(sum-a[3][(i+j)%n]);
                    s.insert(h);
                }
                ull h = 0;
                forn(i,n) h = h*seed+a[0][i];
                forn(i,n) {
                    ull hh = 0;
                    forn(j,n){
                        hh = hh*seed+a[1][(i+j)%n];
                    }
                    b[0][i] = hh;
                }
                forn(i,n) {
                    ull hh = 0;
                    forn(j,n){
                        hh = hh*seed+a[2][(i+j)%n];
                    }
                    b[1][i] = hh;
                }
                forn(i,n){
                    forn(j,n){
                        if(s.find(h+b[0][i]+b[1][j])!=s.end()){
                            win = 1;
                            break;
                        }
                    }
                    if(win) break;
                }
            }
            cout<<"Case "<<casee<<": ";
            if(win) cout<<"Yes"<<'
    ';
            else cout<<"No"<<'
    ';
        }   
        return 0;
    }
    
  • 相关阅读:
    B/S---控件属性
    Windows Form -----内容(11)
    C#--Web控件简介
    C#控件基本1
    C#增删改小总结
    C#播放器控件的常用方法介绍
    C#封装---小练
    链接SQL、事务---小总结
    事务-----2
    事务----1
  • 原文地址:https://www.cnblogs.com/AlexPanda/p/12520285.html
Copyright © 2011-2022 走看看