文章目录
-
- A - A + B Problem HDU - 1000
- B - Sum Problem HDU - 1001
- C - Let the Balloon Rise HDU - 1004
- D - Number Sequence HDU - 1005
- E - Elevator HDU - 1008
- F - Least Common Multiple HDU - 1019
- G - Digital Roots HDU - 1013
- H - 计算两点间的距离 HDU - 2001
- I - 计算球体积 HDU - 2002
- J - 求绝对值 HDU - 2003
- K - 第几天? HDU - 2005
- L - 成绩转换 HDU - 2004
- M - 求奇数的乘积 HDU - 2006
- N - 平方和与立方和 HDU - 2007
- O - 数值统计 HDU - 2008
- P - 求数列的和 HDU - 2009
- Q - 水仙花数 HDU - 2010
- R - 多项式求和 HDU - 2011
- S - 素数判定 HDU - 2012
- T - 蟠桃记 HDU - 2013
- U - 青年歌手大奖赛_评委会打分 HDU - 2014
- V - 偶数求和 HDU - 2015
- W - 数据的交换输出 HDU - 2016
- X - 字符串统计 HDU - 2017
- Y - 母牛的故事 HDU - 2018
- Z - 数列有序! HDU - 2019
A - A + B Problem HDU - 1000
水题
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
int a, b;
while (cin >> a >> b)
cout << a + b << endl;
return 0;
}
B - Sum Problem HDU - 1001
水题
#include<map>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
int a, b, sum = 0;
while (cin >> b) {
sum = 0;
for (int i = 1; i <= b; i++)
sum += i;
cout << sum << endl << endl;
}
return 0;
}
C - Let the Balloon Rise HDU - 1004
使用map记录每个字符串的出现次数即可
#include<map>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
map<string,int> m;
int num;
while (cin >> num){
if (num == 0)
break;
string max;
int cnt_max = 0;
m.clear();
while (num--) {
string s;
cin >> s;
m[s]++;
if (cnt_max < m[s]) {
cnt_max = m[s];
max = s;
}
}
cout << max << endl;
}
return 0;
}
D - Number Sequence HDU - 1005
矩阵快速幂运算,需先计算出初始矩阵,还有一种打表找规律的解法,可交题ac,但题目本质上是递推公式
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2;
const int mod = 7;
struct matrix {
long long m[maxn][maxn];
matrix() {
memset(m, 0, sizeof(m));
}
};
matrix multi(matrix a, matrix b) {
matrix res;
for (int i = 0; i < maxn; i++)
for (int j = 0; j < maxn; j++)
for (int k = 0; k < maxn; k++)
res.m[i][j] = res.m[i][j] + a.m[i][k] * b.m[k][j] % mod;
return res;
}
matrix fastm(matrix a, int n) {
matrix res;
for (int i = 0; i < maxn; i++)
res.m[i][i] = 1;
while (n) {
if (n & 1)
res = multi(res, a);
a = multi(a, a);
n >>= 1;
}
return res;
}
int main()
{
matrix mar;
long long x, y, n;
while (cin >> x >> y >> n) {
if (x == 0 && y == 0 && n == 0)
break;
mar.m[0][0] = x;
mar.m[0][1] = y;
mar.m[1][0] = 1;
mar.m[1][1] = 0;
if (n <= 2)
cout << "1" << endl;
else {
matrix res = fastm(mar, n - 2);
cout << (res.m[0][0] + res.m[0][1]) % 7 << endl;
}
}
return 0;
}
E - Elevator HDU - 1008
水题
#include<stdio.h>
int main(int argc, const char* argv[])
{
int sum, num = 0,floor,floor1 = 0;;
while (scanf("%d", &num) != EOF)
{
if (num == 0)
break;
sum = 0;
floor = 0;
for (int i = 0; i < num; i++)
{
scanf("%d", &floor1);
if (floor > floor1)
sum