@ZHANGQIANYI2020
HNUCM-OJ 三家人,酷酷的单词,斜线最大最小值,矩阵连乘问题-求最优值,矩阵连乘问题-构造最优解,石子合并问题
问题 A: 三家人
(时间限制: 1 Sec 内存限制: 128 MB)
题目描述:
有三户人家共拥有一作花园,每户人家的太太均需帮忙整理花园。A太太工作了 5天,B太太则工作了 4天,才将花园整理完毕。C 太太因为正身怀六甲无法加入她们的行列,便出了 90 元。请问这笔钱如何分给 A、B二位太太较为恰当?A应得多少元?
90/(5+4)*5=50元?如果这么想你就上当了!正确答案是 60元。如果没想通的话再想想吧。 下面回答一个一般性的问题:假定 A 太太工作了 x 天,B 太太工作了 y 天,C 太太出了 90 元,则 A太太应得多少元?输入保证二位太太均应得到非负整数元钱。
输入:
输入第一行为数据组数T( T <=20)。每组数据仅一行,包含三个整数x ,y ,z(1<= x ,y <=10,1<= z <=1000)。
输出:
对于每组数据,输出一个整数,即 A太太应得的金额(单位:元)。
样例输入:
2
5 4 90
8 4 123
样例输出:
60
123
提示:
本题有个小小的陷阱哦。如果答案错的话,认真检查一下代码吧。
参考答案:
import java.util.Scanner;
public class 三家人 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int T=sc.nextInt();
while(T--<=20){
while(sc.hasNext()) {
int x=sc.nextInt();
int y=sc.nextInt();
int z=sc.nextInt();
int sum=x+y;
sum/=3;
int ans=x-sum+y-sum;
int s=z*(x-sum)/ans;
System.out.println(s);
}
}
}
}
问题 B: 酷酷的单词
(时间限制: 1 Sec 内存限制: 128 MB)
题目描述:
输入一些仅由小写字母组成的单词。你的任务是统计有多少个单词是“酷”的,即每种字母出 现的次数都不同。
比如 ada 是酷的,因为 a 出现 2 次,d 出现 1 次,而 1 和 2 不同。再比如,banana 也是酷的, 因为 a 出现 3 次,n 出现 2 次,b 出现 1 次。但是,bbacccd 不是酷的,因为 a 和 d 出现的次数 相同(均为 1次)。
输入:
输入包含不超过 30 组数据。每组数据第一行为单词个数 n (1<=n<=10000)。以下 n 行各包含一 个单词,字母个数为 1~30。
输出:
对于每组数据,输出测试点编号和酷单词的个数。
样例输入:
2
ada
bbacccd
2
illness
a
样例输出:
Case 1: 1
Case 2: 0
参考答案:
import java.util.Scanner;
public class 酷酷的单词 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int x=1;
while(sc.hasNext()) {
int n=sc.nextInt();
int number=n;
int count=0;
while(n>=0) {
String s=sc.nextLine();
char[] ch=s.toCharArray();
if(ch.length==1) {
count++;
}
int temp[]=new int[99];
for(int i=0;i<temp.length;i++) {
temp[i]=0;
}
int flag=0;
for(int i=0;i<ch.length;i++) {
for(int j=0;j<ch.length;j++) {
if(ch[i]==ch[j]) {
flag++;
}
}
if(temp[flag]==0)
temp[flag]=ch[i];
else if(temp[flag]!=ch[i]) {
count++;
break;
}
flag=0;
}
n--;
}
System.out.println("Case "+x+": "+(number-count));
count=0;
x++;
}
x=