题
第五周
Bernard的组合数
problem description
Bernard想知道在所有不同的组合数值中,第k小的组合数值是多少呢。
给定一个k,返回第k小的组合数值。
input
多组输入
一个整数 t 表示有 t 组数据
每组数据中包含一个数字k
其中(1 t
100, 1
k
10^100)
output
t行,每一行一个整数,输出第k小的组合数的值
sample input
2
1
6
sample output
1
6
说明
标程
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
while (~scanf("%d", &t)) {
while (t--) {
char a[100];
scanf("%s", a);
printf("%s\n", a);
}
}
return 0;
}⑨⑨⑨感冒灵
problem description
夏天天气炎热,Bernard吹空调不盖被子感冒了,不过好在有⑨⑨⑨感冒灵。Bernard服用过后效果显著,Bernard想知道他多久能好。但是Bernard非常调皮,感冒了也依然不盖被子,所以每过一天,他的病情就会加重,当他的病情超过一定数值是他就会嗝屁。
input
多组输入
输入四个数a,b,c,d,分别代表干感冒的初始值a,最后嗝屁的危险值b,每天增加的病情值c,和感冒药的治疗效果d。
每天先吃感冒药在睡觉,睡觉的时候病情加重,如果当天病情值降到0一下,则感冒痊愈,到第二天早上,病情达到危险值是嗝屁,一直治不好也会嗝屁。
output
输出Bernard感冒需要再过几天才能痊愈(当天吃药病好了不算一天),行末换行,如果Bernard嗝屁了输出 "bad ending" 不包含引号。
sample input
3 1 0 2
3 4 2 1
3 4 1 1
3 4 1 2
sample output
bad ending
bad ending
bad ending
1
说明
case1:当天直接超过危险值嗝屁
case2:第二天超过危险值嗝屁
case3:一直治不好嗝屁
case4:第二天痊愈
标程
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
// freopen("in1.txt","r",stdin);
// freopen("out2.txt","w",stdout);
while (~scanf("%d%d%d%d", &a, &b, &c, &d)) {
//还没吃药就嗝屁了(初始值大于等于危险值)
//或者第一天吃药治不好并且一直治不好(每天增加的病情值大于治疗的病情值)
if (a >= b || (a > d && c >= d)) {
printf("bad ending\n");
continue;
} else if (a == 0 || a <= d)
printf("0\n"); //没病或者第一天就治好了
else if ((a - d) % (d - c) == 0)
printf("%d\n", (a - d) / (d - c));
else
printf("%d\n", (a - d) / (d - c) + 1);
}
return 0;
}高飞的秘密情书
problem description
受众多妹子青睐的高飞学长收到过很多情书,其中就有一封奇特的情书引起他的注意。
很可惜这是被加密过了的,于是高飞学长想知道情书的内容,终于破解了加密手段,如下:
情书中只包含英文小写字符'a-z',对应的每一个小写字符对应的取该字符后距离为d的字符,举个栗子,d=3,则a被替换为d,b被替换为e,c被替换为f,d被替换为g......z被替换为c。
input
多组输入
第一行包含一个整数d,表示字符的偏移量
第二行为一串加密字符串
字符串长度<1000,0<d<26
output
输出原字符串
sample input
1
jmpwfzpv
sample output
iloveyou
标程
#include <bits/stdc++.h>
using namespace std;
char s[27] = "abcdefghijklmnopqrstuvwxyz";
int main() {
int d;
while (~scanf("%d", &d)) {
char a[1005];
char ans[1005];
int pos[1005];
getchar();
gets(a);
int size = strlen(a);
for (int i = 0; i < 26; ++i) {
pos[s[i]] = i;
}
for (int i = 0; i < size; ++i) {
ans[i] = s[(pos[a[i]] + 26 - d) % 26];
}
for (int i = 0; i < size; ++i)
printf("%c", ans[i]);
printf("\n");
}
}⑨的超大气球
problem description
一天⑨获得了一个气球,他想让这个气球变得足够大,在每个单位时间内向气球内部吹入x体积的气体,可惜搞怪的Bernard在气球的前方距离d的位置放了一个钉子,⑨提前发现了这点,为了让气球足够大,他将会在t时刻停止吹气球
input
两个整数d和x,分别代表钉子距离气球的距离和每单位时间内吹入的气球气体体积,为方便计算取3,气球近似看为一个球体
output
结果保留一位小数,表示在t时刻停止吹气
sample input
1 3
sample output
13.5
标程
#include <bits/stdc++.h>
using namespace std;
const int pi = 3;
int main() {
int x, d;
while (~scanf("%d%d", &x, &d)) {
printf("%.1lf\n", d * d * d / 2.0 / x);
}
return 0;
}
查看11道真题和解析