HDU 2033-2035 人见人爱系列

原题链接:http://acm.hdu.edu.cn/showproblem.php?pid = 2033
水题,超过60取模即可.

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
    int n;
while(~scanf("%d",&n)){
while(n--){
    long long a[7]={0};
    for(int i=0;i<6;i++){
    scanf("%lld",&a[i]);    
    }
    for(int j=2;j>=0;j--){
        a[j]+=a[j+3];
        if(j!=0&&a[j]>=60)
        {
            a[j-1]+=(a[j]/60);
            a[j]=a[j]%60;
        }
    }
    for(int i=0;i<=2;i++){
        if(i==0)
        printf("%lld",a[i]);
        else
        printf(" %lld",a[i]);
    }
    printf("\n");
    }
}
    return 0;
}

HDU 2034 A-B
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2034
集合问题
按题目意思就能做
用C++试试.

#include<iostream>  
#include<stdio.h>  
#include<algorithm>  
#include<string.h>  
using namespace std;  
#define N 105  
#define M 10000000000  
int a[N],b[N];  
int main()  
{  
    int n,m,x,i,j,cnt,f;  


    while(scanf("%d%d",&n,&m),n+m)  
    {  
        for(i=0;i<n;i++)  
            scanf("%d",&a[i]);  
        for(i=0;i<m;i++)  
            scanf("%d",&b[i]);  
        sort(a,a+n);  
        cnt=0;  
        for(i=0;i<n;i++)  
        {  
            f=0;  
            for(j=0;j<m;j++)  
                if(a[i]==b[j])  
                {  
                    f=1;  
                    break;  
                }     

            if(f==0)  
            {  
                printf("%d ",a[i]);  
                cnt++;  
            }  
        }  
        if(cnt==0)  
            printf("NULL");  
        printf("\n");  
    }  
    return 0;  
}  

HDU 2035,快速幂取余.
本来以为对后三位数就是对1000取余,后来发现HDU弹出超出数据范围或者错误答案,才发现事情并没有那么简单
这里用到了快速幂取余公式
http://blog.csdn.net/baidu_20363843/article/details/49559573
最简单的快速幂取幂,已经贴在注释中了.
看了教程才会的

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int pow_mod(int a,int p);
int main(int argc, char *argv[]) {
int a,b;
while(scanf("%d%d",&a,&b)!=EOF){
    if(a==0&&b==0) break;
    printf("%d\n",pow_mod(a,b));

}
    return 0;
}

int pow_mod(int a,int p){
    if(p==0) return 1;
    int ans=pow_mod(a,p/2);
    ans=ans*ans%1000;
    if(p%2==1) ans=ans*a%1000;
    return ans;
}
//int PowerMod(int a, int b, int c)  
//{  
//int ans = 1;  
//a = a % c;  
//while(b>0)  
//{  
//   
//if(b % 2 = = 1)  
//ans = (ans * a) % c;  
//b = b/2;  
//a = (a * a) % c;  
//}  
//return ans;  
//}  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值