虽然会时不时很难过,但是终于还是缓过来了,不抛弃,不放弃,继续coding,继续战斗......
题目来源:http://acm.hdu.edu.cn/listproblem.php?vol=11 中2051~2099
题解code如下(部分,其它陆续更新中):
#2051: 十进制转化为二进制题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2051
<span style="font-size:12px;">#include <iostream></span>
#include <cstdio>
#include <stack>
using namespace std;
stack<int> s;
int n;
int main(){
while(scanf("%d",&n)!=EOF){
while(!s.empty()) s.pop();
while(n){
s.push(n%2);
n/=2;
}
while(!s.empty()){
printf("%d",s.top());
s.pop();
}
printf("\n");
}
return 0;
}
#2052:Picture:直接模拟
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2052
#include <iostream>
#include <cstdio>
using namespace std;
int n,m;
int main(){
while(scanf("%d%d",&n,&m)!=EOF){
for(int i=0;i<=m+1;i++){
for(int j=0;j<=n+1;j++){
if((i==0&&j==0)||(i==0&&j==n+1)||(i==m+1&&j==0)||(i==m+1&&j==n+1)) printf("+");
else if(i==0 || i==m+1) printf("-");
else if(j==0 || j==n+1) printf("|");
else printf(" ");
}
printf("\n");
}
printf("\n");
}
return 0;
}
#2053:Switch Game:直接模拟,找约数的个数
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2053
#include <iostream>
#include <cstdio>
using namespace std;
#define ll __int64
ll n,count;
int main(){
while(scanf("%I64d",&n)!=EOF){
count=0;
for(ll i=1;i<=n;i++)
if(n%i==0) count++;
if(count%2==0) printf("0\n");
else printf("1\n");
}
return 0;
}
#2055:An easy problem:真的很easy
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2055
#include <iostream>
#include <cstdio>
using namespace std;
int t,x,y;
char c[2];
int main(){
scanf("%d",&t);
while(t--){
scanf("%s%d",c,&y);
if(c[0]>='a' && c[0]<='z') x=-(c[0]-'a'+1);
else x=c[0]-'A'+1;
printf("%d\n",x+y);
}
return 0;
}
#2057:A + B Again
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2057
解题报告:http://blog.youkuaiyun.com/qinlumoyan/article/details/39010923
#2063:过山车:二分匹配
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2063
解题报告:http://blog.youkuaiyun.com/qinlumoyan/article/details/38454815
#2066:一个人的旅行:最短路
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2066
解题报告:http://blog.youkuaiyun.com/qinlumoyan/article/details/38390451
#2070:Fibbonacci Number:注意类型就可题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2070
#include <iostream>
#include <cstdio>
using namespace std;
#define ll __int64
const int MAXN = 50+5;
int n;
ll f[MAXN];
int main(){
f[0]=0;f[1]=1;
for(int i=2;i<MAXN;i++)
f[i]=f[i-1]+f[i-2];
while(scanf("%d",&n)!=EOF && n!=-1){
printf("%I64d\n",f[n]);
}
return 0;
}
#2071:求最高的身高:优先队列,排序,记录最大值(最简单的)均可
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2071
#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
int t,n;
double num;
int main(){
priority_queue<double> q;
scanf("%d",&t);
while(t--){
while(!q.empty())q.pop();
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%lf",&num);
q.push(num);
}
printf("%.2lf\n",q.top());
q.pop();
}
return 0;
}
#2072:单词数:map的应用
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2072
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
string str;
map<string,int> w;
int main(){
while(getline(cin,str) && str[0]!='#'){
w.clear();
int len=str.size();
string arr;
int ans=0;
for(int i=0;i<len;i++){
if(str[i]==' ' || i+1==len){
if(arr!="" && !w[arr]){
w[arr]=1;
ans++;
}
arr="";
}
else{
arr+=str[i];
}
}
printf("%d\n",ans);
}
return 0;
}
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2075
#include <iostream>
#include <cstdio>
using namespace std;
int a,b,t;
int main(){
scanf("%d",&t);
while(t--){
scanf("%d%d",&a,&b);
printf(a%b==0 ? "YES\n" : "NO\n");
}
return 0;
}
# 2081:手机短号:6+后5位
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2081
//完全不能理解不用字符型做就是过不了。。。
//#include <iostream>
//#include <cstdio>
//using namespace std;
//
//int n;
//long long num,ans;
//
//int main(){
// scanf("%d",&n);
// while(n--){
// ans=600000;
// scanf("%lld",&num);
// num%=100000;
// ans+=num;
// printf("%lld\n",ans);
// }
// return 0;
//}
//AC code:
#include<cstdio>
using namespace std;
int n,i;
char arr[12];
int main(){
scanf("%d",&n);
while(n--){
scanf("%s",arr);
printf("6%s\n",arr+6);
}
return 0;
}
# 2083:简易版最短距离:排序求解
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2083
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN = 500+10;
int t,n,ans,mid;
int d[MAXN];
int abs(int a){return a>0 ? a : -a;}
int main(){
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",d+i);
sort(d,d+n);
mid=d[n/2];
ans=0;
for(int i=0;i<n;i++)
ans+=abs(d[i]-mid);
printf("%d\n",ans);
}
return 0;
}
#2087:剪花布条
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2087
解题报告:http://blog.youkuaiyun.com/qinlumoyan/article/details/38981651
#2088:Box of Bricks
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2088
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 50;
int n,h[MAXN],sum,avg,ans;
int flag=0;
int main(){
while(scanf("%d",&n)!=EOF && n){
if(flag) printf("\n");
flag=1;
memset(h,0,sizeof(h));
sum=0;ans=0;
for(int i=0;i<n;i++){
scanf("%d",&h[i]);
sum+=h[i];
}
avg=sum/n;
for(int i=0;i<n;i++)
if(h[i]<avg) ans+=avg-h[i];
printf("%d\n",ans);
}
return 0;
}
#2089:不要62:数位DP
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2089
解题报告:http://blog.youkuaiyun.com/qinlumoyan/article/details/28091409
#2090:算菜价
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2090
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char veg[100];
double num,pri,sum;
int main(){
sum=0;
while(scanf("%s%lf%lf",veg,&num,&pri)!=EOF)
sum+=num*pri;
printf("%.1lf\n",sum);//printf自带四舍五入的功能,根据你定义的精度
return 0;
}
#2091:空心三角形:注意输出格式的问题呀!
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2091
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char ch;
int n;
int main(){
int flag=0;
while(scanf("%s%d",&ch,&n)!=EOF && ch!='@'){
if(flag) printf("\n");
flag=1;
for(int i=0;i<n-1;i++){
for(int j=0;j<n+i;j++){
if(j==n-i-1 || j==n+i-1) printf("%c",ch);
else printf(" ");
}
printf("\n");
}
for(int i=0;i<2*n-1;i++)
printf("%c",ch);
printf("\n");
}
return 0;
}
#2092:整数解:分情况进行模拟,注意各个情况的边界。
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2092
#include <iostream>
#include <cstdio>
using namespace std;
int n,m,flag,tmp;
int abs(int x){return x>0?x:-x;}
int main(){
while(scanf("%d%d",&n,&m)!=EOF && (n||m)){
flag=0;
tmp=abs(n)>abs(m)?abs(n):abs(m);
if(n>0 && m>0){
for(int i=1;i<=m;i++)
if(i*(n-i)==m){printf("Yes\n");flag=1;break;}
if(!flag) printf("No\n");
}
else{
for(int i=-tmp;i<=tmp;i++)
if(i*(n-i)==m){printf("Yes\n");flag=1;break;}
if(!flag)printf("No\n");
}
}
return 0;
}
#2093:
#2094:产生冠军
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2094
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
const int MAXN = 1000+10;
map<string,int> str;
int indeg[MAXN];
int n;
char str1[100],str2[100];
int main(){
while(scanf("%d",&n)!=EOF && n){
str.clear();
memset(indeg,0,sizeof(indeg));
int tmp=1;
for(int i=1;i<=n;i++){
scanf("%s%s",&str1,&str2);
if(!str[str1]) str[str1]=tmp++;
if(!str[str2]) str[str2]=tmp++;
indeg[str[str2]]++;
}
int count=0;
for(int i=1;i<=n;i++)
if(indeg[i]==0)
count++;
if(count==1) printf("Yes\n");
else printf("No\n");
}
return 0;
}
#2095:find your present (2):异或的应用:选择奇数项
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2095
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int n,num,ans;
int main(){
while(scanf("%d",&n)!=EOF && n){
ans=0;
for(int i=1;i<=n;i++){
scanf("%d",&num);
ans^=num;
}
printf("%d\n",ans);
}
return 0;
}
#2096:小明A+B:直接模拟
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2096
#include <iostream>
#include <cstdio>
using namespace std;
int t,a,b,ans;
int main(){
scanf("%d",&t);
while(t--){
scanf("%d%d",&a,&b);
a%=100;b%=100;
ans=(a+b)%100;
printf("%d\n",ans);
}
return 0;
}
#2097:Sky数:十进制、十二进制、十六进制各位之和是否相等。
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2097
#include <iostream>
#include <cstdio>
using namespace std;
int n,nums,nume,numl,ns,ne,nl;
int main(){
while(scanf("%d",&n)!=EOF && n){
ns=ne=nl=n;
nums=nume=numl=0;
while(ns){
nums+=ns%10;
ns/=10;
nume+=ne%12;
ne/=12;
numl+=nl%16;
nl/=16;
}
if(nums==nume && nums==numl) printf("%d is a Sky Number.\n",n);
else printf("%d is not a Sky Number.\n",n);
}
return 0;
}
#2098:分拆素数和:先将素数打表,然后遍历判断,能构成该数的两个数是否为素数即可。
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2098
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
const int MAXN=10000+10;
int num,ans,isp[MAXN],vis[MAXN];
void init_prime(){
memset(isp,0,sizeof(isp));
for(int i=2;i<=MAXN;i++)
if(!vis[i]){
isp[i]=1;
for(int j=i*i;j<=MAXN;j+=i){
vis[j]=1;
}
}
}
int main(){
init_prime();
while(scanf("%d",&num)!=EOF&&num){
ans=0;
for(int i=2;i<=num;i++){
if(isp[i]&&isp[num-i]&&i!=(num-i)) ans++;
}
printf("%d\n",ans/2);
}
return 0;
}
#2099:整除的尾数:将给出的数乘以100,再加上1至99之间的数进行遍历,如果能够整除,则满足条件。
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2099
#include <iostream>
#include <cstdio>
using namespace std;
int a,b,flag,m;
int main(){
while(scanf("%d%d",&a,&b)!=EOF && (a||b)){
flag=0;
a*=100;
for(int i=0;i<100;i++){
m=a+i;
if(m%b==0){
if(flag) printf(" ");
flag=1;
printf("%02d",i);
}
}
printf("\n");
}
return 0;
}