ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

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

2019-11-11 21:50:35  阅读:270  来源: 互联网

标签:11 ch int LL while 光棍节 2019.11 include getchar


题目链接:

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

T2:Problem 2 魔塔 (tower.cpp)

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

 

思路:

T1:打表找规律

T2:暴力

T3:状压dp

 

代码:

T1:

#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
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;
}/*
template<typename T>inline 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<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
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<queue>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
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<<n)-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<<n)-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

 

标签:11,ch,int,LL,while,光棍节,2019.11,include,getchar
来源: https://www.cnblogs.com/ydclyq/p/11838721.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有