校内日常膜你赛————2019.11.11(光棍节快乐

题目链接:

T1:Problem 1 DIY 手工 (diy.cpp)

T2:Problem 2 魔塔 (tower.cpp)

T3:Problem 3 趣味运动会 (sport.cpp)

 

思路:

T1:打表找规律

T2:暴力

T3:状压dp

 

代码:

T1:

#include 
#include 
#include 
#include 
#include 
using namespace std;
typedef long long LL;
LL maxn;
LL ksm(LL x,LL y) {
    LL z=1;
    while(y) {
        if(y&1)z*=x;
        y>>=1;
        x*=x;
    }
    return z;
}/*
templateinline void read(T &x) {
    x=0;
    char ch=getchar();
    T f=1;
    while(!isdigit(ch)) {
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    x=x*f;
}*/
void write(LL x) {
    if(x<0) {
        putchar('-');
        write(-x);
    } else {
        if(x/10) write(x/10);
        putchar(x%10+'0');
    }
}
int main() {
    // freopen("diy.in","r",stdin);
    // freopen("diy.out","w",stdout);
    int T;
    scanf("%d",&T);
    while(T--) {
        LL N;
        maxn=0;
        scanf("%lld",&N);
        if(N%3==0) {
            printf("%lld\n",ksm(N/3,3));
            continue;
        } else {
            for(int i=3; i<=10; i++) {
                for(int j=3; j<=10; j++) {
                    if(N%i==0 && N%j==0 && N%(N-(N/i+N/j))==0) {
                        maxn=max(maxn,(N/i)*(N/j)*(N-(N/i+N/j)));
                    }
                }
            }
            if(!maxn) puts("-1");
            else {
                write(maxn);
                puts("");
            }
        }
    }
    return 0;
}
View Code

T2:

#include
#include
#include
#include
using namespace std;
int T,n,k,v[10],sum;
struct node {
    int a[10],b[10];
    int sum;
} f[100001];
bool vis[100001];
void out(int k) {
    if(k==0) {
        cout<<0<<" ";
        return ;
    }
    int num=0,ch[50];
    while(k>0) ch[++num]=k%10,k/=10;
    while(num) putchar(ch[num--]+48);
    putchar(32);
}
inline int read() {
    int x=0;
    char ch=getchar();
    while(ch<'0'||ch>'9')ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x;
}
bool check(int now) {
    for(int i=1; i<=k; i++)    if(f[now].a[i]>v[i])return false;
    return true;
}
void jia(int now) {
    for(int i=1; i<=k; i++) v[i]+=f[now].b[i];
}
int main() {
//    freopen("tower.in","r",stdin);
//    freopen("tower.out","w",stdout);
    T=read();
    while(T--) {
        n=read(),k=read();
        sum=0;
        memset(vis,false,sizeof vis);
        for(int ll=1; ll<=k; ll++)v[ll]=read();
        for(int i=1; i<=n; i++) {
            for(int j=1; j<=k; j++) f[i].a[j]=read();
            for(int j=1; j<=k; j++) f[i].b[j]=read();
        }
        bool l;
        while(1) {
            l=false;
            for(int i=1; i<=n; i++) {
                if(vis[i])continue;
                if(check(i)) jia(i),l=true,sum++,vis[i]=true;
            }
            if(l==false) break;
        }
        out(sum);
        printf("\n");
        for(int i=1; i<=k; i++)out(v[i]);
        printf("\n");
    }
//    fclose stdin;
//    fclose stdout;
    return 0;
}
View Code

T3:

#include<set>
#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long ll;
const int mod=1e9+7;
inline int read() {
    int x=0;
    char ch=getchar();
    while(ch>'9'||ch<'0')ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x;
}
int ans[10],f[1<<11][6];
int main() {
    int T=read();
    while(T--) {
        int n=read(),m=read();
        memset(ans,0,sizeof ans);
        memset(f,0,sizeof f);
        f[0][0]=1;
        while(m--) {
            char c=getchar();
            while(c!='-'&&c!='+')c=getchar();
            int u=read(),v=read();
            if(c=='+') {
                int kk=(1<1;
                int t=(1<<(u-1))|(1<<(v-1));
                kk^=t;
                for(int i=kk;; i=(i-1)&kk) {
                    for(int j=1; j<=n/2; ++j) {
                        f[i | t][j] += f[i][j - 1];
                        f[i | t][j] >= mod ? f[i | t][j] -= mod : 0;
                        ans[j] += f[i][j - 1];
                        ans[j] >= mod ? ans[j] -= mod : 0;
                    }
                    if(!i)break;
                }
            } else {
                int kk=(1<1;
                int t=(1<<(u-1))|(1<<(v-1));
                kk ^= t;
                for(int i = kk;; i = (i - 1) &kk) {
                    for(int j = 1; j <= n / 2; ++j) {
                        f[i | t][j] -= f[i][j - 1];
                        f[i | t][j] < 0 ? f[i | t][j] += mod : 0;
                        ans[j] -= f[i][j - 1];
                        ans[j] < 0 ? ans[j] += mod : 0;
                    }
                    if(!i) break;
                }
            }
            for(int i = 1; i < n / 2; ++i) printf("%d ",(ans[i] + mod) % mod);
            printf("%d\n",(ans[n / 2] + mod) % mod);
        }
    }
    return 0;
}
View Code

 

你可能感兴趣的:(校内日常膜你赛————2019.11.11(光棍节快乐)