2016 :: 合肥

A 暴力 bitset

#include <bits/stdc++.h>
using namespace std;
int T,n;
char s[2055][2055];
bitset<2017> bit1[2017],bit2[2017];
int main()
{
    scanf("%d",&T);
    while (T--) {
        scanf("%d",&n);
        for (int i=1;i<=n;++i)
            scanf("%s",s[i]+1);
        for (int i=1;i<=n;++i) {
            bit1[i].reset();
            bit2[i].reset();
        }
        for (int i=1;i<=n;++i)
            for (int j=1;j<=n;++j)
                if (s[i][j]=='P')
                    bit1[i][j]=1;
                else if (s[i][j]=='Q')
                    bit2[i][j]=1;
        bool flag=true;
        for (int i=1;i<=n;++i) {
            for (int j=1;j<=n;++j)
                if (bit1[i][j]) {
                    if ((bit1[i]&bit1[j])!=bit1[j]) {
                        flag=false;
                        break;
                    }
                }
            if (!flag)
                break;
        }
        if (flag)
        for (int i=1;i<=n;++i) {
            for (int j=1;j<=n;++j)
                if (bit2[i][j]) {
                    if ((bit2[i]&bit2[j])!=bit2[j]) {
                        flag=false;
                        break;
                    }
                }
            if (!flag)
                break;
        }
        puts(flag?"T":"N");
    }
    return 0;
}
View Code

C 博弈 kugwzk.info

#include <bits/stdc++.h>
#define maxn 40010
#define inf 0x3f3f3f3f
#define REP(i,x,y) for(int i=x;i<(y);i++)
#define RREP(i,x,y) for(int i=x;i>(y);i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
vector<pii>e[maxn];
int n,m,par[maxn],sum[maxn];
void dfs(int rt,int fa,int len) {
    sum[rt]+=len;
    for(int i=0;i<e[rt].size();i++) {
        int nxt=e[rt][i].first;
        if(nxt==fa) continue;
        par[nxt]=rt;
        sum[rt]+=e[rt][i].second;
        dfs(nxt,rt,e[rt][i].second);
    }
    sort(e[rt].begin(),e[rt].end());
}
int main()
{
    int T;scanf("%d",&T);
    while(T--) {
        scanf("%d %d",&n,&m);
        for(int i=1;i<=n;i++) e[i].clear(),sum[i]=0,par[i]=0;
        REP(i,1,n) {
            int u,v,w;scanf("%d %d %d",&u,&v,&w);
            e[u].push_back(make_pair(v,w));
            e[v].push_back(make_pair(u,w));
        }
        dfs(1,0,0);
        //REP(i,1,n+1) cout<<i<<" "<<sum[i]<<endl;
        while(m--) {
            int op;scanf("%d",&op);
            if(op==0) {
                int x;scanf("%d",&x);
                if(sum[x]%2==1) puts("Girls win!");
                else puts("Boys win!");
            }
            else {
                int x,y,z;scanf("%d %d %d",&x,&y,&z);
                if(par[x]==y) swap(x,y);
                auto it=lower_bound(e[x].begin(),e[x].end(),make_pair(y,-1));
                int tmp=(*it).second;
                (*it).second=z;
             //  cout<<(*it).second<<endl;
                if(tmp==1&&z==0) {
                    sum[x]--;
                    sum[y]--;
                }
                else if(tmp==0&&z==1) {
                    sum[x]++;
                    sum[y]++;
                }
            }

        }
    }
}
View Code

E 正解递推,DP卡过

#include <bits/stdc++.h>
using namespace std;
const int maxn=10005;
const int mod=1e8+7;
int dp[maxn][17],n,a[maxn];
int T1[20][350],T2[20][350];
char s[maxn];
int cnt[20];
bool check(int num,int i,int j){
    int s1[4];
    int s2[4];
    for (int t = 0; t <4 ;t++)
        s1[t] = i%2,i/=2;
    for (int t = 0; t <4 ;t++)
        s2[t] = j%2,j/=2;
    int sum = 0;
    for (int t = 0; t < 4 ; t++){
        sum += s2[t];
    }
    sum += s1[0] + s1[1];
    if (sum!=num) return false;
    if (s1[2]!=s2[0]) return false;
    if (s1[3]!=s2[1]) return false;
    return true;
}
int main()
{
    for (int cn = 0; cn <= 6 ;cn++){
    for (int i=0;i<16;++i)
        for (int j=0;j<16;++j) {
            if (check(cn,i,j)){
                ++cnt[cn];
                //cout << cn << " " << i <<" " << j << endl;
                T1[cn][cnt[cn]] = i;
                T2[cn][cnt[cn]] = j;
            }
        }
    }
    int T;
    scanf("%d",&T);
    while (T--) {
        scanf(" %s",s+1);
        n=strlen(s+1);
        for (int i=1;i<=n;++i)
            a[i]=s[i]-'0';
        memset(dp,0,sizeof dp);
        dp[0][0]= dp[0][4] = dp[0][8] = dp[0][12] = 1;
        for (int i=1;i<=n;++i){
            for (int t = 1; t<=cnt[a[i]] ; t++){
                dp[i][T2[a[i]][t]] = (dp[i][T2[a[i]][t]] + dp[i-1][T1[a[i]][t]]) % mod;
            }
        }
        int res=0;
        for (int i=0;i<4;++i)
            res = (res + dp[n][i]) % mod;
        printf("%d\n",res);
    }
    return 0;
}
View Code

H 暴力

#include <bits/stdc++.h>
#define maxn 100010
#define inf 0x3f3f3f3f
#define REP(i,x,y) for(int i=x;i<(y);i++)
#define RREP(i,x,y) for(int i=x;i>(y);i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int n,a[110];
vector<pii>vec;
int main()
{
    int T;scanf("%d",&T);
    while(T--) {
        scanf("%d",&n);
        vec.clear();
        for(int i=0;i<=n;i++) a[i]=0;
        REP(i,1,n+1) {
            scanf("%d",&a[i]);
            a[i]^=a[i-1];
        }
        int m;scanf("%d",&m);
        for(int i=0;i<n;i++) {
            for(int j=i+1;j<=n;j++) {
                int tmp=a[i]^a[j];
                vec.push_back(make_pair(tmp,j-i));
            }
        }
        REP(i,1,m+1) {
            int x;scanf("%d",&x);
            int minn=inf,len=0;
            REP(i,0,vec.size()) {
                if(minn>abs(vec[i].first-x)||(minn==abs(vec[i].first-x)&&len<vec[i].second)) minn=abs(vec[i].first-x),len=vec[i].second;
            }
            printf("%d\n",len);
        }
        puts("");
    }
}
View Code

I 二进制递归

#include <bits/stdc++.h>
const long long mod = 1e9+7;
const double ex = 1e-10;
#define inf 0x3f3f3f3f
using namespace std;
long long solve(long long x,long long y){
    if (x==0&&y==0) return 0;
    long long tx = x;
    long long ty = y;
    long long temx = 1LL,temy = 1LL;
    while (tx!=0) tx/=2LL,temx *=2LL;
    temx/=2LL;
    while (ty!=0) ty/=2LL,temy *=2LL;
    temy/=2LL;
    if (temx != temy){
        return max(temx,temy)*2-1;
    }
    else {
        return temx + solve(x-temx,y-temy);
    }
}
int main()
{
    int T;
    scanf("%d",&T);
    while (T--){
        long long x,y;
        scanf("%I64d%I64d",&x,&y);
        printf("%I64d\n",solve(x,y));

    }
    return 0;
}
View Code

J 【补】

#include <bits/stdc++.h>
long long mod = 1e9+7;
const double ex = 1e-10;
#define inf 0x3f3f3f3f
using namespace std;
long long c;
int f(int x,int y)
{
     c = 0;
     int t;
     while (y>0)
     {
          c +=1;
          t = x % y;
          x = y;
          y = t;
     }
     return x;
}
long long get(long long a,long long b,long long c,long long n){
    if (n<=0) return 0;
    if (n==1) return (b/c) % mod;
    long long tmp = 0;
    tmp += (a/c)%mod*((n-1)*n/2%mod)%mod;
    tmp %= mod;
    tmp += (b/c)*(n)%mod;
    tmp %= mod;
    a = a%c;
    b = b%c;
    if (a==0) return tmp;
    else return (tmp+get(c,(a*n+b)%c,a,(a*n+b)/c)) % mod;
}
long long F(long long x, long long y){
    long long ans = 0;
    for (long long i = 1; i <= y ; i++){
        for (long long j = 0; j<i; j++){
            if (j==0&&i!=1) continue;
            long long a = j;
            if ( a == 0 ) a = 1;
            long long b = i;
            if (f(a,b) == 1){
                long long n = (x-a)/b + 1;
                a = a*b;
                b = b*b;
                ans = (ans + get(b,a,c,n)) % mod;
            }
        }
    }
    return ans;
}
int main()
{
    int T;
    cin >> T;
    while (T--){
        long long x;
        long long y;
        long long p;
        scanf("%I64d%I64d%I64d",&x,&y,&p);
        mod = p;
        long long ans = 0;
        for (int i = 1 ; i <= y ; i++){
            ans = (ans + F(x/i,y/i)) % mod;
        }
        printf("%I64d\n",ans);
    }
    return 0;
}
View Code

 

posted @ 2017-09-17 20:30  myhappinessisall  阅读(153)  评论(0编辑  收藏  举报