2013腾讯编程马拉松初赛第一场 (hdu4505、hdu4506、hdu4508、hdu4509)

hdu4505:

水题,思路很清晰

#include <iostream>
#include <list>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;

const int N=121;
typedef long long LL;

int xh[105];

int main()
{
    int i,t,n,m,a;
    cin>>t;
    while(t--)
    {
        memset(xh,0,sizeof(xh));
        cin>>n;
        m=n;
        int max=0;//max记录最高层
        while(m--)
        {
            scanf("%d",&a);
            if(max<a)   max=a;
            xh[a]++;//a层人数+1
        }

        int temp=0,sum=0;//temp记录上一次电梯停的层数,sum总共需要多长时间
        for(i=0;i<=max;i++)
        {
            while(xh[i]==0) i++;
            sum+=xh[i]+(i-temp)*6+5;//下的人时间+上升的时间+开门5秒
            temp=i;
        }
        sum+=max*4;//下降的时间
        cout<<sum<<endl;
    }
    return 0;
}




hdu4506:

可以看出来,新的值是在原来某一个值*k^t

用快速幂就ok了

#include <iostream>
#include <list>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;

const int N=10021;
const int mod=1000000007;
typedef __int64 LL;

LL n,xh[N],k,t;

LL powkt()
{
    LL a=k,b=t,x=1;
    while(b)
    {
        if(b%2==1)
            x=(x*a)%mod;
        b/=2;
        a=(a*a)%mod;
    }
    return (x)%mod;
}

int main()
{
    int i,T,j;
    cin>>T;
    while(T--)
    {
        scanf("%I64d%I64d%I64d",&n,&t,&k);
        for(i=1;i<=n;i++)
            scanf("%I64d",&xh[i]);
        LL kt=powkt();//求k^t
        int s=0;
        t%=n;
        if(t==0)
            s=1;
        else
            s=n-t+1;
        for(i=1;i<=n;i++)
        {

            if(i!=1)
                printf(" ");
            printf("%I64d",(kt*xh[s])%mod);
            s++;
            if(s>n)
                s=1;
        }
        printf("\n");
    }
    return 0;
}




hdu4508:

完全背包,好久都没敲dp了,手都生了。

#include <iostream>
#include <list>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;

const int N=121;
typedef long long LL;

int w[N],v[N],dp[100010];//这个地方dp别写成N了
int n,maxv;

int main()
{
    int i,j;
    while(cin>>n)
    {
        for(i=1;i<=n;i++)
            scanf("%d%d",&w[i],&v[i]);
        scanf("%d",&maxv);
        memset(dp,0,sizeof(dp));
        for(i=1;i<=n;i++)
            for(j=v[i];j<=maxv;j++)
                dp[j]=max(dp[j],dp[j-v[i]]+w[i]);
        printf("%d\n",dp[maxv]);
    }
    return 0;
}




hdu4509

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值