Problem Description

Your objective for this question is to develop a program which will generate a fibbonacci number. The fibbonacci function is defined as such:

f(0) = 0

f(1) = 1

f(n) = f(n-1) + f(n-2)

Your program should be able to handle values of n in the range 0 to 50.

Input

Each test case consists of one integer n in a single line where 0≤n≤50. The input is terminated by -1.

Output

Print out the answer in a single line for each test case.

Sample Input

3

4

5

-1

Sample Output

2

3

5

Hint

Note:

you can use 64bit integer: __int64

额,式子都给出来了,直接码上

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std; int n;
long long f[51]; int main() {
f[0] = 0;
f[1] = 1;
for (int i = 2; i <= 50; i++)
f[i] = f[i - 1] + f[i - 2];
while (scanf("%d", &n) != EOF) {
if (n == -1) break;
printf("%lld\n", f[n]);
}
return 0;
}

Problem Description

There are some students in a class, Can you help teacher find the highest student .

Input

There are some cases. The first line contains an integer t, indicate the cases; Each case have an integer n ( 1 ≤ n ≤ 100 ) , followed n students’ height.

Output

For each case output the highest height, the height to two decimal plases;

Sample Input

2

3 170.00 165.00 180.00

4 165.00 182.00 172.00 160.00

Sample Output

180.00

182.00

大小比较!

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std; int n, m;
double ans; int main() {
while (scanf("%d", &n) != EOF) {
while (n--) {
scanf("%d", &m);
ans = 0.0;
while (m--) {
double a;
scanf("%lf", &a);
if (a > ans) ans = a;
}
printf("%.2lf\n", ans);
}
}
return 0;
}

Problem Description

lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词的总数。下面你的任务是帮助xiaoou333解决这个问题。

Input

有多组数据,每组一行,每组就是一篇小文章。每篇小文章都是由小写字母和空格组成,没有标点符号,遇到#时表示输入结束。

Output

每组只输出一个整数,其单独成行,该整数代表一篇文章里不同单词的总数。

Sample Input

you are my friend

'#'(为了排版手动加了个单引号qwq)

Sample Output

4

因为要统计不同的单词数,所以很容易想到使用set

这里现学了一个东西:istringstream,它可以绑定一行字符串,然后以空格为分隔符把该行分隔开来,方便!

PS:还有一种切割制胡窜的方法是使用strtok来切割,它的优点在于,可以指定任意字符作为分隔符来切割单词

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <set>
#include <sstream>
using namespace std; string s; int main() {
while (getline(cin, s)) {
if (s == "#") break;
istringstream oula(s);
set<string> word;
string ss;
while (oula >> ss) word.insert(ss);
int ans = word.size();
cout << ans << endl;
}
return 0;
}

Problem Description

甜甜从小就喜欢画图画,最近他买了一支智能画笔,由于刚刚接触,所以甜甜只会用它来画直线,于是他就在平面直角坐标系中画出如下的图形:



甜甜的好朋友蜜蜜发现上面的图还是有点规则的,于是他问甜甜:在你画的图中,我给你两个点,请你算一算连接两点的折线长度(即沿折线走的路线长度)吧。

Input

第一个数是正整数N(≤100)。代表数据的组数。

每组数据由四个非负整数组成x1,y1,x2,y2;所有的数都不会大于100。

Output

对于每组数据,输出两点(x1,y1),(x2,y2)之间的折线距离。注意输出结果精确到小数点后3位。

Sample Input

5

0 0 0 1

0 0 1 0

2 3 3 1

99 99 9 9

5 5 5 5

Sample Output

1.000

2.414

10.646

54985.047

0.000

一开始没思路啊,看了大佬的题解才会了,哎

其实就是要求两点间的距离,可以转化为先求出两个点分别到原点的距离,然后相减

然后我们看一下张图,可以发现图中的线大致可以分为两种:

一种是有点的线(例如(0,1)和(1,0);(0,2)和(2,0);(0,3)和(3,0)......)

一种是没有点的线(例如(0,1)和(0,0);(0,2)和(1,0);(0,3)和(2,0)......)

然后算就好了

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std; int n, x1, x2, z1, y2; double cal(int x, int y) {
double sum1 = 0, sum2 = 0;
double num = sqrt(2.0);
int cnt = x + y;
for (int i = 0; i < cnt; i++) //计算没有点的边
sum1 += sqrt(pow(i, 2) + pow(i + 1, 2));
for (int i = 1; i < cnt; i++) sum2 += i * num; ////计算有点的边
sum2 += x * num;
sum2 += sum1;
return sum2;
} int main() {
while (scanf("%d", &n) != EOF) {
while (n--) {
scanf("%d%d%d%d", &x1, &z1, &x2, &y2);
if (x1 + z1 > x2 + y2) {
swap(x1, x2);
swap(z1, y2);
}
double ans;
ans = cal(x2, y2) - cal(x1, z1);
printf("%.3lf\n", ans);
}
}
return 0;
}

Problem Description

需要的时候,就把一个个大小差一圈的筐叠上去,使得从上往下看时,边筐花色交错。这个工作现在要让计算机来完成,得看你的了。

Input

输入是一个个的三元组,分别是,外筐尺寸n(n为满足0<n<80的奇整数),中心花色字符,外筐花色字符,后二者都为ASCII可见字符;

Output

输出叠在一起的筐图案,中心花色与外筐花色字符从内层起交错相叠,多筐相叠时,最外筐的角总是被打磨掉。叠筐与叠筐之间应有一行间隔。

Sample Input

11 B A

5 @ W

Sample Output

 AAAAAAAAA
ABBBBBBBBBA
ABAAAAAAABA
ABABBBBBABA
ABABAAABABA
ABABABABABA
ABABAAABABA
ABABBBBBABA
ABAAAAAAABA
ABBBBBBBBBA
AAAAAAAAA @@@
@WWW@
@W@W@
@WWW@
@@@

模拟就行

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std; int n, flag;
char c1, c2;
char a[81][81]; int main() {
while (scanf("%d %c %c", &n, &c1, &c2) != EOF) {
if (flag == 1) printf("\n");
flag = 1;
if (n == 1) {
printf("%c\n", c1);
continue;
}
for (int i = 0; i <= n / 2; i++) {
char num;
if ((n / 2) % 2 == 0) {
if (i % 2 == 0) num = c1;
else num = c2;
} else {
if (i % 2 == 0) num = c2;
else num = c1;
}
for (int j = i; j < n - i; j++) {
a[i][j] = num;
a[n - i - 1][j] = num;
a[j][i] = num;
a[j][n - i - 1] = num;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if ((i == 0 && j == 0) || (i == 0 && j == n - 1) || (i == n - 1 && j == 0) || (i == n - 1 && j == n - 1))
printf(" ");
else printf("%c", a[i][j]);
}
printf("\n");
}
}
return 0;
}

Problem Description

正整数A是否能被正整数B整除,不知道为什么xhd会研究这个问题,来帮帮他吧。

Input

输入数据的第一行是一个数据T,表示有T组数据。

每组数据有两个正整数A和B(A,B<10^9)。

Output

对于每组输入数据,输出"YES"表示可以被整除,"NO"表示不能被整除。

Sample Input

2

4 2

5 3

Sample Output

YES

NO

在这位置就是来搞笑的一道题,无坑放心做

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std; int t;
long long a, b; int main() {
while (scanf("%d", &t) != EOF) {
while (t--) {
scanf("%lld%lld", &a, &b);
if (a % b == 0) printf("YES\n");
else printf("NO\n");
}
}
return 0;
}
  • HDU2076 夹角有多大(题目已修改,注意读题)

    题目链接

Problem Description

时间过的好快,一个学期就这么的过去了,xhd在傻傻的看着表,出于对数据的渴望,突然他想知道这个表的时针和分针的夹角是多少。现在xhd知道的只有时间,请你帮他算出这个夹角。

注:夹角的范围[0,180],时针和分针的转动是连续而不是离散的。

Input

输入数据的第一行是一个数据T,表示有T组数据。

每组数据有三个整数h(0 <= h < 24),m(0 <= m < 60),s(0 <= s < 60)分别表示时、分、秒。

Output

对于每组输入数据,输出夹角的大小的整数部分。

Sample Input

2

8 3 17

5 13 30

Sample Output

138

75

初中的时候学的如何计算时针和分针的夹角,应该是物理,当初在学而思学这的个记得很清楚

时针走:30°/h = 0.5°/m = (1 / 120)°/s

分针走: 6°/m = 0.1°/s

所以时针的角度为30 * h + m / 2 + s / 120,分针的角度为:6 * m + s / 10;

则夹角为abs(30 * h + m / 2 + s / 120 - 6 * m - s / 10)

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std; int t, h, m, s; int main() {
while (scanf("%d", &t) != EOF) {
double ans;
while (t--) {
scanf("%d%d%d", &h, &m, &s);
if (h >= 12) h -= 12;
ans = abs(30 * h + m / 2.0 + s / 120.0 - 6 * m - s * 0.1);
if (ans > 180) ans = 360 - ans;
printf("%.0lf\n", floor(ans));
}
}
return 0;
}

Problem Description

还记得汉诺塔III吗?他的规则是这样的:不允许直接从最左(右)边移到最右(左)边(每次移动一定是移到中间杆或从中间移出),也不允许大盘放到小盘的上面。xhd在想如果我们允许最大的盘子放到最上面会怎么样呢?(只允许最大的放在最上面)当然最后需要的结果是盘子从小到大排在最右边。

Input

输入数据的第一行是一个数据T,表示有T组数据。

每组数据有一个正整数n(1 <= n <= 20),表示有n个盘子。

Output

对于每组输入数据,最少需要的摆放次数。

Sample Input

2

1

10

Sample Output

2

19684

上个汉诺塔的题的代码拿来简单一改即可

这次可以把最大的那个盘子放在最上面,那么只需弄好n-1个(这些的操作方法和之前那题是一样的,所以需要先计算出来并储存在一个数组f[n]里),直接输出f[n-1]+2即可

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std; int t;
long long dp[36]; int main() {
dp[1] = 2;
for (int i = 2; i <= 35; i++) dp[i] = dp[i - 1] * 3 + 2;
while (scanf("%d", &t) != EOF) {
while (t--) {
int n;
scanf("%d", &n);
printf("%lld\n", dp[n - 1] + 2);
}
}
return 0;
}

Problem Description

为了能过个好年,xhd开始复习了,于是每天晚上背着书往教室跑。xhd复习有个习惯,在复习完一门课后,他总是挑一门更简单的课进行复习,而他复习这门课的效率为两门课的难度差的平方,而复习第一门课的效率为100和这门课的难度差的平方。xhd这学期选了n门课,但是一晚上他最多只能复习m门课,请问他一晚上复习的最高效率值是多少?

Input

输入数据的第一行是一个数据T,表示有T组数据。

每组数据的第一行是两个整数n(1 <= n <= 40),m(1 <= m <= n)。

接着有n行,每行有一个正整数a(1 <= a <= 100),表示这门课的难度值。

Output

对于每组输入数据,输出一个整数,表示最高效率值。

Sample Input

2

2 2

52

25

12 5

89

64

6

43

56

72

92

23

20

22

37

31

Sample Output

5625

8836

一开始没看到题目中的“但是一晚上他最多只能复习m门课”这一句,迷惑了好久为啥样例输出这么大,最后才看见“最多”二字,那就好办了,直接复习并且仅最简单的一门效率肯定最大

好家伙,真是好的复习方法

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#define INF 101
using namespace std; int t, n, m, a, ans; int main() {
while (scanf("%d", &t) != EOF) {
while (t--) {
ans = INF;
scanf("%d%d", &n, &m);
while (n--) {
scanf("%d", &a);
if (ans > a) ans = a;
}
printf("%d\n", (100 - ans) * (100 - ans));
}
}
return 0;
}

Problem Description

又到了选课的时间了,xhd看着选课表发呆,为了想让下一学期好过点,他想知道学n个学分共有多少组合。你来帮帮他吧。(xhd认为一样学分的课没区别)

Input

输入数据的第一行是一个数据T,表示有T组数据。

每组数据的第一行是两个整数n(1 <= n <= 40),k(1 <= k <= 8)。

接着有k行,每行有两个整数a(1 <= a <= 8),b(1 <= b <= 10),表示学分为a的课有b门。

Output

对于每组输入数据,输出一个整数,表示学n个学分的组合数。

Sample Input

2

2 2

1 2

2 1

40 8

1 1

2 2

3 2

4 2

5 8

6 9

7 6

8 8

Sample Output

2

445

一道单纯的多重背包问题,直接上代码

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std; int t, n, k;
int dp[41];
struct node{
int a;
int b;
}num[41]; int main() {
while (scanf("%d", &t) != EOF) {
while (t--) {
memset(dp, 0, sizeof(dp));
scanf("%d%d", &n, &k);
for (int i = 1; i <= k; i++)
scanf("%d%d", &num[i].a, &num[i].b);
dp[0] = 1;
for (int i = 1; i <= k; i++)
for (int j = n; j >= num[i].a; j--)
for (int l = 1; l <= num[i].b; l++) {
if (j - num[i].a * l >= 0)
dp[j] += dp[j - num[i].a * l];
else break;
}
printf("%d\n", dp[n]);
}
}
return 0;
}

HDU100题简要题解(2070~2079)的更多相关文章

  1. HDU100题简要题解(2060~2069)

    这十题感觉是100题内相对较为麻烦的,有点搞我心态... HDU2060 Snooker 题目链接 Problem Description background: Philip likes to pl ...

  2. HDU100题简要题解(2080~2089)

    //2089之前忘做了,周二C语言课上做,至于2086,写题解的时候突然发现之前的做法是错的,新的解法交上去CE,等周二再弄吧,其余题目暂时可以放心 HDU2080 夹角有多大II 题目链接 Prob ...

  3. HDU100题简要题解(2050~2059)

    HDU2050 折线分割平面 题目链接 Problem Description 我们看到过很多直线分割平面的题目,今天的这个题目稍微有些变化,我们要求的是n条折线分割平面的最大数目.比如,一条折线可以 ...

  4. HDU100题简要题解(2000~2009)

    前言(废话): 从11月6号到11月20号,断断续续做了有三个星期,总算整完了,之后会慢慢整理汇总到这里 中间部分用到数学知识的十几道题边学边做直接把我这个数学菜鸟做到怀疑人生 11.6~11.10又 ...

  5. HDU100题简要题解(2040~2049)

    HDU2040 亲和数 题目链接 Problem Description 古希腊数学家毕达哥拉斯在自然数研究中发现,220的所有真约数(即不是自身的约数)之和为: 1+2+4+5+10+11+20+2 ...

  6. HDU100题简要题解(2030~2039)

    HDU2030 汉字统计 题目链接 Problem Description 统计给定文本文件中汉字的个数. Input 输入文件首先包含一个整数n,表示测试实例的个数,然后是n段文本. Output ...

  7. HDU100题简要题解(2020~2029)

    HDU2020 绝对值排序 题目链接 Problem Description 输入n(n<=100)个整数,按照绝对值从大到小排序后输出.题目保证对于每一个测试实例,所有的数的绝对值都不相等. ...

  8. HDU100题简要题解(2010~2019)

    HDU2010 水仙花数 题目链接 Problem Description 春天是鲜花的季节,水仙花就是其中最迷人的代表,数学上有个水仙花数,他是这样定义的: "水仙花数"是指一个 ...

  9. 【HNOI2019】部分题简要题解

    题意懒得写了 LOJ Day 1 T1 鱼 个人做法比较猎奇,如果有哪位大佬会证明能分享一下的话感激不尽. 题解:枚举鱼尾和鱼身的交点D,将所有其他点按照到D的距离排序,距离相同的分一组. 感性的理解 ...

随机推荐

  1. Curl可以模拟浏览器

    curl直接访问被拒绝 [22:10:00 root@C7 ~]#curl -I www.163.com HTTP/1.1 403 Forbidden Date: Wed, 24 Jun 2020 0 ...

  2. apktool重新打包添加签名

    一.生成apk apktool b 反编译后项目目录 -o 新apk名称.apk 二.生成签名 keytool -genkeypair -alias 新apk名称.apk -keyalg RSA -v ...

  3. ssm整合之springmvc.xml文件

    <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...

  4. RAM ROM区别记忆

    我老是忘这个 1.概念 RAM即随机存储内存,这种存储器在断电时将丢失其存储内容,故主要用于存储短时间使用的程序.ROM即只读内存,是一种只能读出事先所存数据的固态半导体存储器. 2.对比 手机中的R ...

  5. Camera2使用surface支持

    surfaceview是运行在子线程,可以为相机提供不断的刷新 public class MainActivity extends AppCompatActivity { public void on ...

  6. vue table切换 (不使用路由功能)

    背景: 一个小场景,感觉使用路由功能太浪费了,考虑用一个简单的类控制 实例代码 //v-for 实现循环<ul class="nav-bar"> <li v-fo ...

  7. Windows定时任务copy到nfs目录

    @echo off mount 192.168.5.10:/data/test x: xcopy /y "D:\backup\mysql\20200316_230000.sql.tar.gz ...

  8. 教你如何使用github+jsDelivr搭建免费图床

    前言 之前写了一篇文章,教你如何使用Typora+PicGo实现图片自动上传到图床 . 这里我用的是七牛图床,七牛图床有一定的免费使用量(没记错的话应该是10个G),如果你的存储量超过这个大小就需要付 ...

  9. Python爬虫urllib模块

    Python爬虫练习(urllib模块) 关注公众号"轻松学编程"了解更多. 1.获取百度首页数据 流程:a.设置请求地址 b.设置请求时间 c.获取响应(对响应进行解码) ''' ...

  10. [Luogu P2831] 愤怒的小鸟 (状压DP)

    题面: 传送门:https://www.luogu.org/problemnew/show/P2831 Solution 首先,我们可以先康一康题目的数据范围:n<=18,应该是状压或者是搜索. ...