HDU100题简要题解(2000~2009)
前言(废话):
从11月6号到11月20号,断断续续做了有三个星期,总算整完了,之后会慢慢整理汇总到这里
中间部分用到数学知识的十几道题边学边做直接把我这个数学菜鸟做到怀疑人生
11.6~11.10又恰逢暨南大学华为杯网络安全挑战赛,一日三餐均为面包,从早肝到晚,肝了5天,累到半死。也因此颓了一周
有的题会重要写一下思路,大部分题题解应该会比较简单不会赘述(有的跨时太久可能也忘了
如有不正确的地方还请不吝赐教,我会十分感谢
下面进入正题
- HDU2000 ASCII码排序
 题目链接
Problem Description
输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。
Input
输入数据有多组,每组占一行,有三个字符组成,之间无空格。
Output
对于每组输入数据,输出一行,字符中间用一个空格分开。
Sample Input
qwe
asd
zxc
Sample Output
e q w
a d s
c x z
十分单纯的比较大小问题,直接上代码
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
char a, b, c;
int main() {
  while (scanf("%c%c%c", &a, &b, &c) != EOF) {
    getchar();
    if (a > b) {
      char d = a;
      a = b;
      b = d;
    }
    if (a > c) {
      char d = a;
      a = c;
      c = d;
    }
    if (b > c) {
      char d = b;
      b = c;
      c = d;
    }
    printf("%c %c %c\n", a, b, c);
  }
  return 0;
}
- HDU2001 计算两点间的距离
 题目链接
Problem Description
输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离。
Input
输入数据有多组,每组占一行,由4个实数组成,分别表示x1,y1,x2,y2,数据之间用空格隔开。
Output
对于每组输入数据,输出一行,结果保留两位小数。
Sample Input
0 0 0 1
0 1 1 0
Sample Output
1.00
1.41
十分简单的小学数学问题,不多说
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
double x1, x2, z1, z2;
double ans;
int main() {
  while (scanf("%lf%lf%lf%lf", &x1, &z1, &x2, &z2) != EOF) {
    ans = sqrt((x1 - x2) * (x1 - x2) + (z1 - z2) * (z1 - z2));
    printf("%.2lf\n", ans);
  }
  return 0;
}
- HDU2002 计算球体积
 题目链接
Problem Description
根据输入的半径值,计算球的体积。
Input
输入数据有多组,每组占一行,每行包括一个实数,表示球的半径。
Output
输出对应的球的体积,对于每组输入数据,输出一行,计算结果保留三位小数。
Sample Input
1
1.5
Sample Output
4.189
14.137
Hint
"#define PI 3.1415927"
体积大概是高中数学?算就完事
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#define PI 3.1415927
using namespace std;
double r, ans = 1.0;
int main() {
  while (scanf("%lf", &r) != EOF) {
    ans = PI * r * r * r * (4.0 / 3);
    printf("%.3lf\n", ans);
  }
  return 0;
}
- HDU2003 求绝对值
 题目链接
Problem Description
求实数的绝对值。
Input
输入数据有多组,每组占一行,每行包含一个实数。
Output
对于每组输入数据,输出它的绝对值,要求每组数据输出一行,结果保留两位小数。
Sample Input
123
-234.00
Sample Output
123.00
234.00
字面意思,算绝对值
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
double n, m;
int main() {
  while (scanf("%lf", &n) != EOF) {
    m = abs(n);
    printf("%.2lf\n", m);
  }
  return 0;
}
- HDU2004 成绩转换
 题目链接
Problem Description
输入一个百分制的成绩t,将其转换成对应的等级,具体转换规则如下:
90~100为A;
80~89为B;
70~79为C;
60~69为D;
0~59为E;
Input
输入数据有多组,每组占一行,由一个整数组成。
Output
对于每组输入数据,输出一行。如果输入数据不在0~100范围内,请输出一行:“Score is error!”。
Sample Input
56
67
100
123
Sample Output
E
D
A
Score is error!
很简单的判断问题
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
int n;
int main() {
  while (scanf("%d", &n) != EOF) {
    if (n >= 90 && n <= 100) cout << "A" << endl;
    else if (n >= 80 && n <= 89) cout << "B" << endl;
    else if (n >= 70 && n <= 79) cout << "C" <<endl;
    else if (n >= 60 && n <= 69) cout << "D" << endl;
    else if (n >= 0 && n <= 59) cout << "E" << endl;
    else cout << "Score is error!" << endl;
  }
  return 0;
}
- HDU2005 第几天?
 题目链接
Problem Description
给定一个日期,输出这个日期是该年的第几天。
Input
输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sample input ,另外,可以向你确保所有的输入数据是合法的。
Output
对于每组输入数据,输出一行,表示该日期是该年的第几天。
Sample Input
1985/1/20
2006/3/12
Sample Output
20
71
要判断这一年是不是闰年,由于鄙人贫乏的生活常识,还百度了一下什么是闰年......
需要两个数组,一个储存闰年每月的天数,一个储存平年每月的天数
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
int x, y, z;
int day1[13] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int day2[13] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool check(int year) {
  if ((year % 4 ==0 && year % 100 != 0) || year % 400 == 0) return true;
  return false;
}
int main() {
  while (scanf("%d/%d/%d", &x, &y, &z) != EOF) {
    int ans = 0;
    if (check(x)) {
      for (int i = 0; i < y - 1; i++) ans += day1[i];
        ans += z;
  	printf("%d\n", ans);
      } else {
  	for (int i = 0; i < y - 1; i++) ans += day2[i];
  	ans += z;
  	printf("%d\n", ans);
      }
  }
  return 0;
}
- HDU2006 求奇数的乘积
 题目链接
Problem Description
给你n个整数,求他们中所有奇数的乘积。
Input
输入数据包含多个测试实例,每个测试实例占一行,每行的第一个数为n,表示本组数据一共有n个,接着是n个整数,你可以假设每组数据必定至少存在一个奇数。
Output
输出每组数中的所有奇数的乘积,对于测试实例,输出一行。
Sample Input
3 1 2 3
4 2 3 4 5
Sample Output
3
15
就是把是奇数的数都乘起来呗
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
int n, m;
int main() {
  while (scanf("%d", &n) != EOF) {
    int ans = 1;
    while (n--) {
      scanf("%d", &m);
      if (m % 2 == 1) ans *= m;
    }
    printf("%d\n", ans);
  }
  return 0;
}
- HDU2007 平方和与立方和
 题目链接
Problem Description
给定一段连续的整数,求出他们中所有偶数的平方和以及所有奇数的立方和。
Input
输入数据包含多组测试实例,每组测试实例包含一行,由两个整数m和n组成。
Output
对于每组输入数据,输出一行,应包括两个整数x和y,分别表示该段连续的整数中所有偶数的平方和以及所有奇数的立方和。
你可以认为32位整数足以保存结果。
Sample Input
1 3
2 5
Sample Output
4 28
20 152
把区间内的偶数平方,把奇数立方,分别加吧起来
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
int n, m;
long long ans1, ans2;
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    ans1 = 0;
    ans2 = 0;
    if (n > m) {
      int x = n;
      n = m;
      m = x;
    }
    for (int i = n; i <= m; i++) {
      if (i % 2 == 0) ans1 += i * i;
      else ans2 += i * i * i;
    }
    printf("%lld %lld\n", ans1, ans2);
  }
  return 0;
}
- HDU2008 数值统计
 题目链接
Problem Description
统计给定的n个数中,负数、零和正数的个数。
Input
输入数据有多组,每组占一行,每行的第一个数是整数n(n<100),表示需要统计的数值的个数,然后是n个实数;如果n=0,则表示输入结束,该行不做处理。
Output
对于每组输入数据,输出一行a,b和c,分别表示给定的数据中负数、零和正数的个数。
Sample Input
6 0 1 2 3 -1 0
5 1 2 3 4 0.5
0
Sample Output
1 2 3
0 0 5
呃,就是分类统计一下
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
int n, ans1, ans2, ans3;
double m;
int main() {
  while (scanf("%d", &n) != EOF) {
    if (n == 0) break;
    ans1 = ans2 = ans3 = 0;
    while (n--) {
      scanf("%lf", &m);
      if (m > 0.0) ans3++;
      else if (m < 0.0) ans1++;
      else ans2++;
    }
    printf("%d %d %d\n", ans1, ans2, ans3);
  }
  return 0;
}
- HDU2009 求数列的和
 题目链接
Problem Description
数列的定义如下:
数列的第一项为n,以后各项为前一项的平方根,求数列的前m项的和。
Input
输入数据有多组,每组占一行,由两个整数n(n<10000)和m(m<1000)组成,n和m的含义如前所述。
Output
对于每组输入数据,输出该数列的和,每个测试实例占一行,要求精度保留2位小数。
Sample Input
81 4
2 2
Sample Output
94.73
3.41
高中数学,数列求和
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
double n, m, ans;
int main() {
  while (scanf("%lf%lf", &n, &m) != EOF) {
    m--;
    ans = n;
    while (m--) {
      ans += sqrt(n);
      n = sqrt(n);
    }
    printf("%.2lf\n", ans);
  }
  return 0;
}
HDU100题简要题解(2000~2009)的更多相关文章
- HDU100题简要题解(2060~2069)
		这十题感觉是100题内相对较为麻烦的,有点搞我心态... HDU2060 Snooker 题目链接 Problem Description background: Philip likes to pl ... 
- HDU100题简要题解(2080~2089)
		//2089之前忘做了,周二C语言课上做,至于2086,写题解的时候突然发现之前的做法是错的,新的解法交上去CE,等周二再弄吧,其余题目暂时可以放心 HDU2080 夹角有多大II 题目链接 Prob ... 
- HDU100题简要题解(2070~2079)
		HDU2070 Fibbonacci Number 题目链接 Problem Description Your objective for this question is to develop a ... 
- HDU100题简要题解(2050~2059)
		HDU2050 折线分割平面 题目链接 Problem Description 我们看到过很多直线分割平面的题目,今天的这个题目稍微有些变化,我们要求的是n条折线分割平面的最大数目.比如,一条折线可以 ... 
- HDU100题简要题解(2040~2049)
		HDU2040 亲和数 题目链接 Problem Description 古希腊数学家毕达哥拉斯在自然数研究中发现,220的所有真约数(即不是自身的约数)之和为: 1+2+4+5+10+11+20+2 ... 
- HDU100题简要题解(2030~2039)
		HDU2030 汉字统计 题目链接 Problem Description 统计给定文本文件中汉字的个数. Input 输入文件首先包含一个整数n,表示测试实例的个数,然后是n段文本. Output ... 
- HDU100题简要题解(2020~2029)
		HDU2020 绝对值排序 题目链接 Problem Description 输入n(n<=100)个整数,按照绝对值从大到小排序后输出.题目保证对于每一个测试实例,所有的数的绝对值都不相等. ... 
- HDU100题简要题解(2010~2019)
		HDU2010 水仙花数 题目链接 Problem Description 春天是鲜花的季节,水仙花就是其中最迷人的代表,数学上有个水仙花数,他是这样定义的: "水仙花数"是指一个 ... 
- 【HNOI2019】部分题简要题解
		题意懒得写了 LOJ Day 1 T1 鱼 个人做法比较猎奇,如果有哪位大佬会证明能分享一下的话感激不尽. 题解:枚举鱼尾和鱼身的交点D,将所有其他点按照到D的距离排序,距离相同的分一组. 感性的理解 ... 
随机推荐
- go创建http服务
			Go语言这种从零开始使用到解决问题的速度,在其他语言中是完全不可想象的.学过 C++ 的朋友都知道,一到两年大强度的理论学习和实战操练也只能学到这门语言的皮毛,以及知道一些基本的避免错误的方法. 那么 ... 
- ubuntu基于VSCode的C++编程语言的构建调试环境搭建指南
			ubuntu基于VSCode的C++编程语言的构建调试环境搭建指南 首先安装g++ sudo apt install g++ 检查是否安装成功: 在插件栏安装插件c/c++.code runner: ... 
- 解决加密PDF文档无法复制文字的问题
			有的时候在网络上搜索到一篇心仪的PDF文档,想复制其中内容时提示无法复制. 如果只想摘抄其中部分文字内容,可以使用Firefox浏览器打开这篇加密文档. Firefox浏览器自带PDF插件,打开后即可 ... 
- Linux标准重定向-输入-输出-错误-多重
			一切皆文件,都是文件的操作 三种I/O设备 标准的输入输出 程序:指令+数据 读入数据:Input 输出数据:Output 系统中打开一个文件系统自动分配文件描述符,除了0,1,2是固定的,其他的都是 ... 
- springboot入门系列(四):SpringBoot和Mybatis配置多数据源连接多个数据库
			SpringBoot和Mybatis配置多数据源连接多个数据库 目前业界操作数据库的框架一般是 Mybatis,但在很多业务场景下,我们需要在一个工程里配置多个数据源来实现业务逻辑.在SpringBo ... 
- 【Azure微服务 Service Fabric 】因证书过期导致Service Fabric集群挂掉(升级无法完成,节点不可用)
			问题描述 创建Service Fabric时,证书在整个集群中是非常重要的部分,有着用户身份验证,节点之间通信,SF升级时的身份及授权认证等功能.如果证书过期则会导致节点受到影响集群无法正常工作. 当 ... 
- airtest本地连接和远程连接
			一.本地连接 # -*- coding: utf-8 -*-# from poco.drivers.android.uiautomation import AndroidUiautomationPoc ... 
- Easypoi实现excel多sheet表导入导出功能
			Easypoi简化了开发中对文档的导入导出实现,并不像poi那样都要写大段工具类来搞定文档的读写. 第一步引入Easypoi依赖 <!-- 导出文件工具 EasyPoi实现Excel读写管理测试 ... 
- Callable返回执行结果
			使用ExecutorService.Callable.Future实现有返回结果的多线程. public class MainActivity extends AppCompatActivity { ... 
- 从零造就JVM大牛(一)
			引言 从事java的小伙伴大家好,如果你是一名从事java行业的程序员,无论你是小白还是工作多年的老司机,我相信这篇文章一定会给你带来 不同程度的收货不敢说你看完我的文章从此精通jvm打遍天下无对手, ... 
