校内日常膜你赛————2019.11.11(光棍节快乐
题目链接:
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 ",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; }
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(" "); for(int i=1; i<=k; i++)out(v[i]); printf(" "); } // fclose stdin; // fclose stdout; return 0; }