原题链接: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;
//}