ZeptoLab Code Rush 2015

源地址:http://codeforces.com/contest/526

最近做题实在是没有感觉,,略颓废。。

A:暴力枚举

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//#define ONLINE_JUDGE
#define eps 1e-5
#define INF 0x7fffffff
#define FOR(i,a) for((i)=0;i<(a);(i)++)
#define MEM(a) (memset((a),0,sizeof(a)))
#define sfs(a) scanf("%s",a)
#define sf(a) scanf("%d",&a)
#define sfI(a) scanf("%I64d",&a)
#define pf(a) printf("%d\n",a)
#define pfI(a) printf("%I64d\n",a)
#define pfs(a) printf("%s\n",a)
#define sfd(a,b) scanf("%d%d",&a,&b)
#define sft(a,b,c)scanf("%d%d%d",&a,&b,&c)
#define for1(i,a,b) for(int i=(a);i=a;i--)
#define MEM1(a) memset(a,0,sizeof(a))
#define MEM2(a) memset(a,-1,sizeof(a))
const double PI=acos(-1.0);
template T gcd(T a,T b){return b?gcd(b,a%b):a;}
template T lcm(T a,T b){return a/gcd(a,b)*b;}
template inline T Min(T a,T b){return a inline T Max(T a,T b){return a>b?a:b;}
using namespace std;
#define ll __int64
#define pi acos(-1.0);
int n,m;
#define Mod 1000000007
#define N 510
#define M 1000100
const int size = 10010;
const int mod = 9901;
char ch[110];
int main(){
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
//  freopen("out.txt","w",stdout);
#endif
    while(sf(n)!=EOF){
        sfs(ch);
        int flag = 0;
        for(int i=0;in) break;
                int k = i;
                while(k+j=5) break;
                }
                if(num >= 5){
                    flag = 1;
                    break;
                }
            }
            if(flag) break;
        }
        if(flag)
            printf("yes\n");
        else
            printf("no\n");
    }
return 0;
}
B:B题刚开始实在是没想好怎么做。。用了下搜索,,感觉不好使。。

最后看了下别人的想法。。就跟那种数塔一样的,从底层开始遍历,如果相邻两个数目不同,那就弄成相同的,然后把数目往上层叠加,直到第一层。


#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//#define ONLINE_JUDGE
#define eps 1e-5
#define INF 0x7fffffff
#define FOR(i,a) for((i)=0;i<(a);(i)++)
#define MEM(a) (memset((a),0,sizeof(a)))
#define sfs(a) scanf("%s",a)
#define sf(a) scanf("%d",&a)
#define sfI(a) scanf("%I64d",&a)
#define pf(a) printf("%d\n",a)
#define pfI(a) printf("%I64d\n",a)
#define pfs(a) printf("%s\n",a)
#define sfd(a,b) scanf("%d%d",&a,&b)
#define sft(a,b,c)scanf("%d%d%d",&a,&b,&c)
#define for1(i,a,b) for(int i=(a);i=a;i--)
#define MEM1(a) memset(a,0,sizeof(a))
#define MEM2(a) memset(a,-1,sizeof(a))
const double PI=acos(-1.0);
template T gcd(T a,T b){return b?gcd(b,a%b):a;}
template T lcm(T a,T b){return a/gcd(a,b)*b;}
template inline T Min(T a,T b){return a inline T Max(T a,T b){return a>b?a:b;}
using namespace std;
#define ll __int64
#define pi acos(-1.0);
int n,m;
#define Mod 1000000007
#define N 510
#define M 1000100
const int size = 10010;
const int mod = 9901;
int a[M];
int mmax;
int main(){
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
//  freopen("out.txt","w",stdout);
#endif
    while(sf(n)!=EOF){
        int total = (1<<(n+1))-1;
        a[1] = 0;
        for(int i=2;i<=total;i++)
             sf(a[i]);
        int ans=0;
        for(int i=n;i>=1;i--){
            for(int j=(1<>1)] += mmax;
            }
        }
        printf("%d\n",ans);
    }
return 0;
}

C:数据范围好大,,本来想用背包的。。

那么我们可以知道,使得价值最大的背包的容量肯定是 <= 两种糖果重量倍数的公倍数,所以我们枚举数量时,只需要枚举到sqrt(c)就可以了。

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//#define ONLINE_JUDGE
#define eps 1e-5
#define INF 0x7fffffff
#define FOR(i,a) for((i)=0;i<(a);(i)++)
#define MEM(a) (memset((a),0,sizeof(a)))
#define sfs(a) scanf("%s",a)
#define sf(a) scanf("%d",&a)
#define sfI(a) scanf("%I64d",&a)
#define pf(a) printf("%d\n",a)
#define pfI(a) printf("%I64d\n",a)
#define pfs(a) printf("%s\n",a)
#define sfd(a,b) scanf("%d%d",&a,&b)
#define sft(a,b,c)scanf("%d%d%d",&a,&b,&c)
#define for1(i,a,b) for(int i=(a);i=a;i--)
#define MEM1(a) memset(a,0,sizeof(a))
#define MEM2(a) memset(a,-1,sizeof(a))
const double PI=acos(-1.0);
template T gcd(T a,T b){return b?gcd(b,a%b):a;}
template T lcm(T a,T b){return a/gcd(a,b)*b;}
template inline T Min(T a,T b){return a inline T Max(T a,T b){return a>b?a:b;}
using namespace std;
#define ll __int64
#define pi acos(-1.0);
int n,m;
#define Mod 1000000007
#define N 510
#define M 1000100
const int size = 10010;
const int mod = 9901;
int a[M];
int mmax;
int main(){
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
//  freopen("out.txt","w",stdout);
#endif
    ll c,hr,hb,wr,wb;
    while(scanf("%I64d%I64d%I64d%I64d%I64d",&c,&hr,&hb,&wr,&wb)!=EOF){
    	ll ans=0;
    	if(c=wb){
    		ans = c/wb*hb;
    		pfI(ans);
    	}else if(c>=wr && c=0)
    				ans = Max(ans,i*hr+(c-i*wr)/wb*hb);
    			if(c-i*wb>=0)
    				ans = Max(ans,i*hb+(c-i*wb)/wr*hr);
    		}
    		pfI(ans);
    	}
    }
return 0;
}


你可能感兴趣的:(codeforces)