Time Limit: 1000MS
Memory Limit: 65536KB
Problem Description
受李老师的影响,他4岁的孩子明明也开始喜欢传统的二十四点游戏了。不过,李老师觉得孩子太小,传统的二十四点的游戏太难了。于是,他把游戏作了简化:给明明两张牌,只能用一次加法或一次乘法运算,看看明明能不能算出24点来。现在,请你试着帮明明完成他的初级二十四点游戏。
Input
输入仅一行,包含两个数m和n,表示两张牌牌面上的数字大小,用空格分开。其中1<=m,n<=13。
Output
Example Input
Example Output
Hint
知识扩展:二十四点游戏是经典的益智类游戏,属于棋牌类游戏,此类游戏设计,最关键的就是游戏算法,它直接决定了游戏的关卡、游戏的难度以及游戏的可玩性。
Author
A - SDUT 2041 初级二十四点游戏
签到题,判断 m+n 和 m*n 即可。
参考代码:
#include <cstdio>
using namespace std;
int main(int argc, char const *argv[]) {
int m, n;
scanf("%d %d", &m, &n);
if(m+n==24 || m*n==24) printf("Yes\n");
else printf("No\n");
return 0;
}
高数Umaru系列(3)——喵星人
Time Limit: 1000MS Memory Limit: 65536KB
Problem Description
高数巨养了一只喵星人,作为一个负责任的铲屎官,高数巨每天都会去给喵星人买新鲜的猫粮。超市里有3种猫粮,超市很大,每种猫粮都有无限袋,种类及价格如下:
土豪喵豪华版猫粮:12元/袋
小资喵乐享版猫粮:5元/袋
抠脚喵经济版猫粮:2元/袋
多组输入。
对于每组数据,输出一个整数,代表高数巨可以购买猫粮的方案数,每组输出占一行
Example Input
Example Output
Hint
Author
B - SDUT 3352 高数Umaru系列(3)——喵星人
用三层 for 循环枚举每种喵粮的购买数量,如果总花费小于等于 n,则记录一次方案,最后输出总方案数即可。
参考代码:
#include <cstdio>
using namespace std;
int main(int argc, char const *argv[]) {
int n;
while(~ scanf("%d", &n)) {
int ans = 0;
for(int i=0; i<=n/12; ++i) {
for(int j=0; j<=n/5; ++j) {
for(int k=0; k<=n/2; ++k) {
if(i*12+j*5+k*2 <= n) ans++;
}
}
}
printf("%d\n", ans);
}
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
Time Limit: 1000MS
Memory Limit: 65536KB
Problem Description
RE最近为情所困,甚至代码都不想敲了。。天天抽刀断水水更流,举杯消愁愁更愁啊。。对酒哭人生,对月诉衷肠。。。于是身为他的队长的我很是着急啊。。这不校赛已经结束了,于是想要给他从参加校赛的中找个妹子,他是疯子她是傻,与他缠缠绵绵敲代码到天涯。但是不知道参赛者是男的还是妹子,据后台说,男的ID名中的不同字母数都是偶数,而妹子ID名中的不同字母数都是奇数。于是这完全可以编个代码来实现啊,这对于RE来说还不是小菜一碟啊。。但是他喝酒已喝晕。。连字母都认不清了,于是你来帮他写个代码来找妹子吧。如果是男的,则输出“GET OUT!”,如果是妹子的话就输出“I WANT YOU!”。
Input
每一行是一串只有小写字母组成的字符串(不含空格),不超过100个字符。
Output
输出“GET OUT!”或“I WANT YOU!”。
Example Input
Example Output
Hint
Author
C - SDUT 2887 RE选老婆
用数组记录每种字母是否出现过,最后遍历一遍即可得到不同字母的个数。
参考代码:
#include <cstdio>
using namespace std;
int main(int argc, char const *argv[]) {
char s[101];
while(~ scanf("%s", s)) {
bool h[26] = {
false};
for(int i=0; s[i]; ++i) {
h[s[i]-'a'] = true;
}
int cnt = 0;
for(int i=0; i<26; ++i) {
if(h[i]) cnt++;
}
if(cnt%2 == 0) printf("GET OUT!\n");
else printf("I WANT YOU!\n");
}
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
Time Limit: 1000MS
Memory Limit: 65536KB
Problem Description
Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like to collect varies of bones , such as dog’s , cow’s , also he went to the grave …
The bone collector had a big bag with a volume of V ,and along his trip of collecting there are a lot of bones , obviously , different bone has different value and different volume, now given the each bone’s value along his trip , can you calculate out the maximum of the total value the bone collector can get ?
Input
The first line contain a integer T , the number of cases.
Followed by T cases , each case three lines , the first line contain two integer N , V, (N <= 1000 , V <= 1000 )representing the number of bones and the volume of his bag. And the second line contain N integers representing the value of each bone. The third line contain N integers representing the volume of each bone.
Output
One integer per line representing the maximum of the total value (this number will be less than 231).
Example Input
1
5 10
1 2 3 4 5
5 4 3 2 1
Example Output
Hint
Author
D - SDUT 2082 Bone Collector
裸的 01 背包题,不解释。
参考代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 1000;
const int MAXC = 1000;
int main(int argc, char const *argv[]) {
int t, n, c, w[MAXN+1], v[MAXN+1], dp[MAXC+1];
scanf("%d", &t);
while(t--) {
scanf("%d %d", &n, &c);
for(int i=1; i<=n; ++i) {
scanf("%d", &v[i]);
}
for(int i=1; i<=n; ++i) {
scanf("%d", &w[i]);
}
memset(dp, 0, sizeof dp);
for(int i=1; i<=n; ++i) {
for(int j=c; j>=w[i]; --j) {
dp[j] = max(dp[j], dp[j-w[i]]+v[i]);
}
}
printf("%d\n", dp[c]);
}
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
Time Limit: 1000MS
Memory Limit: 32768KB
Problem Description
在一场盛大的集体婚礼中,为了使婚礼进行的丰富一些,司仪临时想出了有一个有意思的节目,叫做"考新郎",具体的操作是这样的:
首先,给每位新娘打扮得几乎一模一样,并盖上大大的红盖头随机坐成一排;
然后,让各位新郎寻找自己的新娘.每人只准找一个,并且不允许多人找一个.
最后,揭开盖头,如果找错了对象就要当众跪搓衣板...
看来做新郎也不是容易的事情...
假设一共有N对新婚夫妇,其中有M个新郎找错了新娘,求发生这种情况一共有多少种可能.
Input
输入数据的第一行是一个整数C,表示测试实例的个数,然后是C行数据,每行包含两个整数N和M(1 < M <= N <= 20)
Output
对于每个测试实例,请输出一共有多少种发生这种情况的可能,每个实例的输出占一行。
Example Input
Example Output
Hint
hdoj2049 有链接提示的题目请先去链接处提交程序,AC后提交到SDUTOJ中,以便查询存档。
Author
HDU LCY 递推求解专题练习
E - SDUT 1021 考新郎
n 个里选 m 个的错排。应用错排公式和组合数公式即可。其中组合数公式为:n! / (m! * (n-m)!)。
参考代码:
#include <cstdio>
using namespace std;
const int MAX = 20;
int main(int argc, char const *argv[]) {
int c, n, m;
long long a[MAX+1] = {
0, 0, 1,}, f[MAX+1] = {
1,};
for(int i=3; i<=MAX; ++i) {
a[i] = (i-1)*(a[i-1]+a[i-2]);
}
for(int i=1; i<=MAX; ++i) {
f[i] = f[i-1] * i;
}
scanf("%d", &c);
while(c--) {
scanf("%d %d", &n, &m);
printf("%lld\n", a[m]*(f[n]/(f[m]*f[n-m])));
}
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
数据结构实验之栈七:出栈序列判定
Time Limit: 30MS Memory Limit: 1000KB
Problem Description
给一个初始的入栈序列,其次序即为元素的入栈次序,栈顶元素可以随时出栈,每个元素只能入栈依次。输入一个入栈序列,后面依次输入多个序列,请判断这些序列是否为所给入栈序列合法的出栈序列。
例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是该压栈序列对应的一个出栈序列,但4,3,5,1,2就不可能是该序列的出栈序列。假设压入栈的所有数字均不相等。
Input
第一行输入整数n(1<=n<=10000),表示序列的长度。
第二行输入n个整数,表示栈的压入顺序。
第三行输入整数t(1<=t<=10)。
后面依次输入t行,每行n个整数,表示要判断的每一个出栈序列。
Output
对应每个测试案例输出一行,如果由初始入栈序列可以得到该出栈序列,则输出yes,否则输出no。
Example Input
51 2 3 4 524 5 3 2 14 3 5 1 2
Example Output
Hint
Author
F - SDUT 3334 数据结构实验之栈七:出栈序列判定
设置一个栈,并设置 2 个变量来存储当前入栈序列和出栈序列的遍历位置。我们可以遍历一下出栈序列,每次循环时,如果当前栈顶符合出栈序列中当前要出栈的数,则直接出栈;否则按入栈序列继续 push。如果入栈完毕而出栈序列依然没有全部符合,则不是合法的出栈序列。
参考代码:
#include <cstdio>
#include <stack>
using namespace std;
int main(int argc, char const *argv[]) {
int n, t, a[10000], b[10000];
scanf("%d", &n);
for(int i=0; i<n; ++i) {
scanf("%d", &a[i]);
}
scanf("%d", &t);
while(t--) {
for(int i=0; i<n; ++i) {
scanf("%d", &b[i]);
}
stack<int> s;
int idx_a = 0, idx_b = 0;
while(idx_b < n) {
if(!s.empty() && s.top()==b[idx_b]) {
s.pop();
idx_b++;
}
else if(idx_a < n) s.push(a[idx_a++]);
else break;
}
if(s.empty()) printf("yes\n");
else printf("no\n");
}
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
数据结构实验之栈七:出栈序列判定
Time Limit: 30MS Memory Limit: 1000KB
Problem Description
给一个初始的入栈序列,其次序即为元素的入栈次序,栈顶元素可以随时出栈,每个元素只能入栈依次。输入一个入栈序列,后面依次输入多个序列,请判断这些序列是否为所给入栈序列合法的出栈序列。
例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是该压栈序列对应的一个出栈序列,但4,3,5,1,2就不可能是该序列的出栈序列。假设压入栈的所有数字均不相等。
Input
第一行输入整数n(1<=n<=10000),表示序列的长度。
第二行输入n个整数,表示栈的压入顺序。
第三行输入整数t(1<=t<=10)。
后面依次输入t行,每行n个整数,表示要判断的每一个出栈序列。
Output
对应每个测试案例输出一行,如果由初始入栈序列可以得到该出栈序列,则输出yes,否则输出no。
Example Input
51 2 3 4 524 5 3 2 14 3 5 1 2
Example Output
Hint
Author
汤圆星の汤圆树
Time Limit: 1000MS Memory Limit: 65536KB
Problem Description
又到了汤圆星球一年一度的汤圆节了,为了筹备节目,汤圆星人需要从汤圆树上采摘小汤圆。
已知汤圆树是汤圆星球的一棵神圣植物,整个汤圆星只有这么一棵,而且只有每年汤圆节才会结果。
每个小汤圆最多与m个小汤圆连接,并且保证没有环。为了保证小汤圆的新鲜,汤圆星人只会采摘最外层的小汤圆,也就是叶子汤圆。
那么问题就来了,为了采够n个汤圆,今年这棵汤圆树最少需要生长为几层高?默认树根为第一层。
Input
输入包含多组,每组两个正整数m,n(2 <= m <= 1000,1 <= n <= 1000000000)。
输入到0 0结束。
Output
对于每组输入,输出最少需要的汤圆层数k,如果无法达到目标,输出-1。
Example Input
Example Output
Hint
Author
LeiQ
G - SDUT 3471 汤圆星の汤圆树
首先要使层数最少,则每层的汤圆必须尽可能连够 m 个汤圆。第 1 层为 1 个,第 2 层为 m 个,之后每一层上的汤圆都会与它的父汤圆和它的 m-1 个子汤圆连接,所以每多一层,都会多出 m-1 个子汤圆,这样,最外层的汤圆数是上一层的 m-1 倍。我们只需要不断累乘,直到最外层汤圆数不小于 n 即可。
另外需要注意特判 n=1 和 m=2 的情况(先自己思考一下为什么)。
参考代码:
#include <cstdio>
using namespace std;
int main(int argc, char const *argv[]) {
int m, n, ans;
while(scanf("%d %d", &m, &n), m|n) {
if(n == 1) ans = 1;
else {
if(m == 2) {
if(n == 2) ans = 2;
else ans = -1;
}
else {
ans = 2;
long long tmp = m;
while(tmp < n) {
tmp *= (m-1);
ans++;
}
}
}
printf("%d\n", ans);
}
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
数据结构实验之栈七:出栈序列判定
Time Limit: 30MS Memory Limit: 1000KB
Problem Description
给一个初始的入栈序列,其次序即为元素的入栈次序,栈顶元素可以随时出栈,每个元素只能入栈依次。输入一个入栈序列,后面依次输入多个序列,请判断这些序列是否为所给入栈序列合法的出栈序列。
例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是该压栈序列对应的一个出栈序列,但4,3,5,1,2就不可能是该序列的出栈序列。假设压入栈的所有数字均不相等。
Input
第一行输入整数n(1<=n<=10000),表示序列的长度。
第二行输入n个整数,表示栈的压入顺序。
第三行输入整数t(1<=t<=10)。
后面依次输入t行,每行n个整数,表示要判断的每一个出栈序列。
Output
对应每个测试案例输出一行,如果由初始入栈序列可以得到该出栈序列,则输出yes,否则输出no。
Example Input
51 2 3 4 524 5 3 2 14 3 5 1 2
Example Output
Hint
Author
今年暑假不AC
Time Limit: 1000MS Memory Limit: 65535KB
Problem Description
“今年暑假不AC?”
“是的。”
“那你干什么呢?”
“看世界杯呀,笨蛋!”
“@#$%^&*%...”
确实如此,世界杯来了,球迷的节日也来了,估计很多ACMer也会抛开电脑,奔向电视了。
作为球迷,一定想看尽量多的完整的比赛,当然,作为新时代的好青年,你一定还会看一些其它的节目,比如新闻联播(永远不要忘记关心国家大事)、非常6+7、超级女生,以及王小丫的《开心辞典》等等,假设你已经知道了所有你喜欢看的电视节目的转播时间表,你会合理安排吗?(目标是能看尽量多的完整节目)
Input
输入数据包含多个测试实例,每个测试实例的第一行只有一个整数n(n<=100),表示你喜欢看的节目的总数,然后是n行数据,每行包括两个数据Ti_s,Ti_e (1<=i<=n),分别表示第i个节目的开始和结束时间,为了简化问题,每个时间都用一个正整数表示。n=0表示输入结束,不做处理。
Output
对于每个测试实例,输出能完整看到的电视节目的个数,每个测试实例的输出占一行。
Example Input
121 33 40 73 815 1915 2010 158 186 125 104 142 90
Example Output
Hint
Author
hdojACM程序设计期末考试
H - SDUT 1703 今年暑假不AC
贪心题,和「SDUT 2073 活动选择问题」几乎是一样的题,不解释。
参考代码:
#include <cstdio>
#include <algorithm>
using namespace std;
struct info {
int s;
int e;
} t[100];
bool cmp(info a, info b) {
return a.e < b.e;
}
int main(int argc, char const *argv[]) {
int n;
while(scanf("%d", &n) && n) {
for(int i=0; i<n; ++i) {
scanf("%d %d", &t[i].s, &t[i].e);
}
sort(t, t+n, cmp);
int st = 0, ans = 0;
for(int i=0; i<n; ++i) {
if(t[i].s >= st) {
ans++;
st = t[i].e;
}
}
printf("%d\n", ans);
}
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32