挺简单的 过了后两道,第一道感觉也快了但是时间不够了,明天再整理整理把第一道题做出来
分礼物
import java.util.HashMap;
import java.util.Scanner;
// 编程题|20.0分2/3
// 回文游戏
// 时间限制:C/C++语言 1000MS;其他语言 3000MS
// 内存限制:C/C++语言 65536KB;其他语言 589824KB
// 题目描述:
// Cassidy和Eleanore是一对好朋友,她们经常会一起玩游戏。某一天她们玩了一个回文游戏。游戏规则是这样的:给出一个仅包含小写字母的字符串S,在每一个人的回合中,她们会进行两个操作:
// 1. 尝试重新排列这个字符串,如果可以把这个字符串排列成回文字符串,则立即获胜。
// 2. 否则,她们必须删掉字符串中的一个字符。
// 已知,Cassidy先手,在两个人都采取最佳策略的情况下,谁可以获胜。
// 输入
// 输入第一行仅包含一个正整数t,表示数据组数,(t<=10)
// 接下来有t行,每行有一个字符串S,表示一组测试数据。(|S|<=1000)
// 输出
// 对于每组数据输出一行,如果Cassidy获胜,则输出Cassidy,否则输出Eleanore
// 样例输入
// 2
// aba
// ab
// 样例输出
// Cassidy
// Eleanore
public class Main2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
String s = sc.next();
boolean Cassidy = func(s);
if (Cassidy || judge1(s)) {
System.out.println("Cassidy");
} else {
System.out.println("Eleanore");
}
}
sc.close();
}
public static boolean func(String s) {
if (judge(s)) {
return true;
}
return false;
}
public static boolean judge(String s) {
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) != s.charAt(s.length() - 1 - i)) {
return false;
}
}
return true;
}
public static boolean judge1(String s) {
HashMap<Character, Integer> hm = new HashMap<>();
for (char i : s.toCharArray()) {
if (hm.get(i) == null) {
hm.put(i, 1);
} else {
hm.remove(i);
}
}
if (hm.isEmpty() || hm.size() <= 1) {
return true;
}
if(hm.size()%2==1){
return true;
}
return false;
}
}
回文游戏
import java.util.HashMap;
import java.util.Scanner;
// 编程题|20.0分2/3
// 回文游戏
// 时间限制:C/C++语言 1000MS;其他语言 3000MS
// 内存限制:C/C++语言 65536KB;其他语言 589824KB
// 题目描述:
// Cassidy和Eleanore是一对好朋友,她们经常会一起玩游戏。某一天她们玩了一个回文游戏。游戏规则是这样的:给出一个仅包含小写字母的字符串S,在每一个人的回合中,她们会进行两个操作:
// 1. 尝试重新排列这个字符串,如果可以把这个字符串排列成回文字符串,则立即获胜。
// 2. 否则,她们必须删掉字符串中的一个字符。
// 已知,Cassidy先手,在两个人都采取最佳策略的情况下,谁可以获胜。
// 输入
// 输入第一行仅包含一个正整数t,表示数据组数,(t<=10)
// 接下来有t行,每行有一个字符串S,表示一组测试数据。(|S|<=1000)
// 输出
// 对于每组数据输出一行,如果Cassidy获胜,则输出Cassidy,否则输出Eleanore
// 样例输入
// 2
// aba
// ab
// 样例输出
// Cassidy
// Eleanore
public class Main2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
String s = sc.next();
boolean Cassidy = func(s);
if (Cassidy || judge1(s)) {
System.out.println("Cassidy");
} else {
System.out.println("Eleanore");
}
}
sc.close();
}
public static boolean func(String s) {
if (judge(s)) {
return true;
}
return false;
}
public static boolean judge(String s) {
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) != s.charAt(s.length() - 1 - i)) {
return false;
}
}
return true;
}
public static boolean judge1(String s) {
HashMap<Character, Integer> hm = new HashMap<>();
for (char i : s.toCharArray()) {
if (hm.get(i) == null) {
hm.put(i, 1);
} else {
hm.remove(i);
}
}
if (hm.isEmpty() || hm.size() <= 1) {
return true;
}
if(hm.size()%2==1){
return true;
}
return false;
}
}
抽卡
import java.util.Arrays;
import java.util.Scanner;
// 抽卡
// 时间限制:C/C++语言 1000MS;其他语言 3000MS
// 内存限制:C/C++语言 131072KB;其他语言 655360KB
// 题目描述:
// 抽卡是一类类似于博弈的游戏。现在有一种抽卡方式,描述如下:
// 初始你只有一次抽卡机会。每次抽卡浪费一次抽卡机会,获得一张卡片。这张卡片上有两个数字,第一个数字代表你能获得的钱,第二个数字代表你能获得的额外抽卡次数。额外的抽卡次数是可以累计的。
// 现在,你知道了卡片的数量,所有的卡片上的数字,以及所有卡片的顺序。你只需要安排一种抽卡顺序,使得你能获得钱数最多。
// 输入
// 第一个行一个数n,代表卡片的数量。 接下来n行,每行用两个数ai,bi描述一张卡片。ai表示抽这张卡能获得的钱数,bi表示抽这张卡能获得的额外抽卡次数。
// 输出
// 一行一个数,代表你能获得的最多钱数。
// 样例输入
// 5
// 0 2
// 1 1
// 1 0
// 1 0
// 2 0
// 样例输出
// 4
// 提示
// 对于100%的数据,0≤a_i,b_i≤1000,1≤n≤1000
// 样例解释:按顺序抽第2,1,5,4张卡
public class Main3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int ans = 0; // 总钱数
int c = 1; // 次数
int[] list = new int[1000];
int list_index = 0;
for (int i = 0; i < n; i++) {
int a = sc.nextInt();
int b = sc.nextInt();
if (b > 0) {
c--;
c += b;
ans += a;
} else {
list[list_index++] = a;
}
}
Arrays.sort(list);
for (int i = 1000 - 1;; i--, c--) {
if (list[i] == 0 || c < 1) {
break;
}
ans += list[i];
}
System.out.println(ans);
sc.close();
}
}