P1000 超级玛丽游戏
********
************
####....#.
#..###.....##....
###.......###### ### ###
........... #...# #...#
##*####### #.#.# #.#.#
####*******###### #.#.# #.#.#
...#***.****.*###.... #...# #...#
....**********##..... ### ###
....**** *****....
#### ####
###### ######
##############################################################
#...#......#.##...#......#.##...#......#.##------------------#
###########################################------------------#
#..#....#....##..#....#....##..#....#....#####################
########################################## #----------#
#.....#......##.....#......##.....#......# #----------#
########################################## #----------#
#.#..#....#..##.#..#....#..##.#..#....#..# #----------#
########################################## ############
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
printf(" ********\n");
printf(" ************\n");
printf(" ####....#.\n");
printf(" #..###.....##....\n");
printf(" ###.......###### ### ###\n");
printf(" ........... #...# #...#\n");
printf(" ##*####### #.#.# #.#.#\n");
printf(" ####*******###### #.#.# #.#.#\n");
printf(" ...#***.****.*###.... #...# #...#\n");
printf(" ....**********##..... ### ###\n");
printf(" ....**** *****....\n");
printf(" #### ####\n");
printf(" ###### ######\n");
printf("##############################################################\n");
printf("#...#......#.##...#......#.##...#......#.##------------------#\n");
printf("###########################################------------------#\n");
printf("#..#....#....##..#....#....##..#....#....#####################\n");
printf("########################################## #----------#\n");
printf("#.....#......##.....#......##.....#......# #----------#\n");
printf("########################################## #----------#\n");
printf("#.#..#....#..##.#..#....#..##.#..#....#..# #----------#\n");
printf("########################################## ############\n");
return 0;
}
P1001 A+B Problem
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
cout << a + b;
return 0;
}
P1421 小玉买文具
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int a, b;
scanf("%d%d", &a, &b);
int num = (a + 0.1 * b) / 1.9;
printf("%d", num);
return 0;
}
P1425 小鱼的游泳时间
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int h1, m1, h2, m2;
scanf("%d%d%d%d", &h1, &m1, &h2, &m2);
if (m2 < m1)
{
m2 += 60;
h2--;
}
m1 = m2 - m1;
h1 = h2 - h1;
printf("%d %d", h1, m1);
return 0;
}
P2181 对角线
注意:
- 问题转化为无序,排列组合
- 当数据范围较大时,可使用高精算法或将变量定义为
"unsigned long long"
类型来解决 - 计算时的技巧,可将
n (n-1) (n-2) * (n-3) / 24 转化为 n (n-1) / 2 (n-2) / 3 * (n-3) / 4
#include <iostream>
using namespace std;
int main()
{
unsigned long long n;
cin >> n;
cout << (n * (n - 1) / 2 * (n - 2) / 3 * (n - 3) / 4) << endl;
return 0;
}
P2433 【深基1-2】小学数学 N 合一
#include<iostream>
// 填上你觉得需要的其他头文件
using namespace std;
int main() {
int T;
cin >> T;
if (T == 1) {
// 粘贴问题 1 的主函数代码,除了 return 0
cout << "I love Luogu!";
} else if (T == 2) {
// 粘贴问题 2 的主函数代码,除了 return 0
cout << 2 + 4 << " " << 10 - 2 - 4;
} else if (T == 3) {
// 请自行完成问题 3 的代码
} else if (T == 4) {
// 请自行完成问题 4 的代码
} else if (T == 5) {
// 请自行完成问题 5 的代码
} else if (T == 6) {
// 请自行完成问题 6 的代码
} else if (T == 7) {
// 请自行完成问题 7 的代码
} else if (T == 8) {
// 请自行完成问题 8 的代码
} else if (T == 9) {
// 请自行完成问题 9 的代码
} else if (T == 10) {
// 请自行完成问题 10 的代码
} else if (T == 11) {
// 请自行完成问题 11 的代码
} else if (T == 12) {
// 请自行完成问题 12 的代码
} else if (T == 13) {
// 请自行完成问题 13 的代码
} else if (T == 14) {
// 请自行完成问题 14 的代码
}
return 0;
}
题解:
- Problem 4中,保留6位有效数字,并非是保留6位小数
- Problem 5中,相遇问题:路程和=时间×速度和。故而,火车过桥问题:总路程=车长+桥长
- Problem 8中,圆的周长:
C=2*π*r
;圆的面积:S=π*r*r
;圆的体积:V=4/3*π*r*r*r
- Prpblem 9中,倒推
- Problem 10中,牛吃草问题
- Problem 11中,相遇问题:路程差÷速度差=追及时间
- Problem 13中,体积相同转化问题
- Problem 14中,薄利多销问题
- 法1:
- 法2:
- 法1:
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
const double pi = 3.141593;
int main()
{
int T;
cin >> T;
if (T == 1)
{
cout << "I love Luogu!" << endl;
}
else if (T == 2)
{
cout << 2 + 4 << " " << 10 - 2 - 4 << endl;
}
else if (T == 3)
{
cout << 3 << endl
<< 12 << endl
<< 2 << endl;
}
else if (T == 4)
{
cout << fixed << setprecision(3) << 500 / 3.0 << endl;
}
else if (T == 5)
{
cout << (220 + 260) / (20 + 12) << endl;
}
else if (T == 6)
{
cout << sqrt(6 * 6 + 9 * 9) << endl;
}
else if (T == 7)
{
cout << 110 << endl
<< 90 << endl
<< 0 << endl;
}
else if (T == 8)
{
cout << pi * 10 << endl
<< pi * 25 << endl
<< 4 / 3.0 * pi * 125 << endl;
}
else if (T == 9)
{
cout << ((((1 + 1) * 2) + 1) * 2 + 1) * 2 << endl;
}
else if (T == 10)
{
cout << 9 << endl;
}
else if (T == 11)
{
cout << 1.0 * 100 / 3 << endl;
}
else if (T == 12)
{
cout << (int)('M' - 'A') + 1 << endl
<< (char)(18 + 'A' - 1) << endl; // 13 R
}
else if (T == 13)
{
cout << (int)pow(4 / 3.0 * pi * (4 * 4 * 4 + 10 * 10 * 10), 1.0 * 1 / 3) << endl; //floor()也可
}
else if (T == 14)
{
cout << 50 << endl;
}
return 0;
}
P5703 【深基2.例5】苹果采购
#include <iostream>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
cout << a * b << endl;
return 0;
}
P5704 【深基2.例6】字母转换
tips:
- 大写改为小写:
cout << char(int(a) + 32) << endl;
- 小写改为大写:
cout << char(int(a) - 32) << endl;
#include <iostream>
using namespace std;
int main()
{
char a;
cin >> a;
cout << char(int(a) - 32) << endl;
return 0;
}
P5705 【深基2.例7】数字反转
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
char a, b, c, d;
scanf("%c%c%c.%c", &a, &b, &c, &d); //用'.'占位
printf("%c.%c%c%c", d, c, b, a); //逐位输出
return 0;
}
P5706 【深基2.例8】再分肥宅水
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double t;
int n;
cin >> t >> n;
cout << fixed << setprecision(3) << t / n << endl;
cout << n*2;
return 0;
}
P5709 【深基2.习6】Apples Prologue
#include <iostream>
using namespace std;
int main()
{
int m, t, s;
cin >> m >> t >> s;
cout << m - (s / t);
return 0;
}
修改:
#include <iostream>
using namespace std;
int main()
{
int m, t, s;
cin >> m >> t >> s;
if (t == 0) //特判t=0的情况
{
cout << 0 << endl;
return 0;
}
if (s % t == 0) //如果s是t的整数倍
{
cout << max(m - s / t, 0) << endl;
}
else //如果不是
{
cout << max(m - s / t - 1, 0) << endl;
}
return 0;
}
P5708 【深基2.习2】三角形面积
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
double a, b, c;
cin >> a >> b >> c;
double p = 0.5 * (a + b + c);
cout << fixed << setprecision(1) << sqrt(p * (p - a) * (p - b) * (p - c)) << endl;
return 0;
}