Description
小邯来参加邯郸学院大学生程序设计竞赛。由于这场比赛在线上举行,有很多需要遵守的规则。有一条规则是,为了避免对题目内容相关的提问被无关的提问淹没,所有和题目内容无关的询问主题都需要将关联题目设置为5-1。
比如,如果选手需要去洗手间,则需要发表新主题进行报备并且设置关联题目为5-1。在去洗手间回来之后,需要在这个主题上发表回复报备。监考人员会记录每次使用洗手间开始时间和结束时间,并且删掉这个主题。
假设小邯往返洗手间需要6分钟,给出小邯发出新主题进行报备的时间和对应主题所设置的关联题目,请计算在符合比赛规则的条件下,他会在什么时候用完洗手间回来。
Input
第一行包含一个字符串T(1 ≤ T ≤ 103),表示数据组数。
接下来T行, 每行包含两个字符串, 第一个字符串为HH:MM的形式, 表示发表报备主题的时间(从08:00到12:00),第二个字符串为5-X的形式,表示报备主题的关联题目。
Output
对于每组数据,输出一行形如HH:MM的字符串,表示小邯用完洗手间回来的时间。
Samplem Input
3
09:10 5-1
10:03 5-6
11:45 5-2
Samplem Ouput
09:16
12:06
12:06
Tip
第一组数据,在提交报备之后小邯就可以走了。
后两组数据,由于关联题目设置有误,此时直接去卫生间违反了比赛规则。因此需要等到12:00比赛结束之后再去,6分钟后也就是12:06回来。
题目来源:2020HBCPC Problem A. 须知
题解
package org.example;
import java.util.Arrays;
import java.util.Scanner;
/**
* @author mumuwei
* @date 2022/4/24
*/
public class PA {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = Integer.parseInt(scanner.nextLine());
for (int i = 0; i<n; i++) {
String next = scanner.nextLine();
String[] s = next.split(" ");
if ("5-1".equals(s[1])) {
String[] times = s[0].split(":");
int hour = Integer.parseInt(times[0]);
int minite = Integer.parseInt(times[1]);
if(minite +6 > 59){
hour++;
minite = minite +6 -60;
} else {
minite = minite +6;
}
String h = hour>=10?""+hour:("0"+hour);
String m = minite>=10?""+minite:("0"+ minite);
System.out.println(h+ ":" + m);
} else {
System.out.println("12:06");
}
}
}
}
Description
2022年北京冬奥会已经圆满闭幕,中国再一次让世界见证什么是了中国力量。在冬奥会期间,小邯发现在竞赛圈有个奇怪的现象,人们称呼奖牌的时候,喜欢使用化学符号Au、Ag和Cu来表示金、银、铜奖,而不是官方的gold、silver和bronze。
他非常无聊,于是就问你,奖牌官方称呼的单词对应的惯用符号是什么。如果他对你说gold,你就要回答他Au,以此类推。
Input
输入一行包含一个字符串,gold、silver或者bronze。
Output
输出对应的惯用符号。
Samplem Input 1
gold
Samplem Ouput 1
Au
Samplem Input 2
silver
Samplem Ouput 2
Ag
Samplem Input 3
bronze
Samplem Ouput 3
Cu
题目来源:2020HBCPC Problem J. 奖牌
题解
package org.example;
import java.util.Scanner;
/**
* @author mumuwei
* @date 2022/4/24
*/
public class PB {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String s = scanner.nextLine();
switch (s){
case "gold":
System.out.println("Au");
break;
case "silver":
System.out.println("Ag");
break;
case "bronze":
System.out.println("Cu");
}
}
}
Description
As we all know, in ACM series, a very important basis for ranking is penalty time.
Xiaohan, a new engineer, has developed an evaluation system. The calculation method of penalty time of the system is as follows:
package org.example;
import java.util.Scanner;
/**
* @author mumuwei
* @date 2022/4/24
*/
public class PC {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
for (int i = 0; i< n; i++) {
String line = scanner.next();
if(line.contains("-")) {
System.out.println(0);
} else {
String[] split = line.split("\\+");
System.out.println(Integer.parseInt(split[0]) + Integer.parseInt(split[1])*20);
}
}
}
}
Description
给你一个整数数组 nums ,请你找出一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。
子数组:数组中的一个连续部分。
Input
输入数据为一行字符串,表示整数数组nums。
1 ≤ nums.length ≤ 105
-104 ≤ nums[i] ≤ 104
Output
输出数组连续子数组中最大的和。
Samplem Input
-2,1,-3,4,-1,2,1,-5,4
Samplem Ouput
6
Tip
连续子数组 [4,-1,2,1] 的和最大,为 6 .
题目来源:53. 最大子数组和 - 力扣(LeetCode) (leetcode-cn.com)
题解
package org.example;
import java.util.Scanner;
/**
* @author mumuwei
* @date 2022/4/24
*/
public class PD {
public static int maxSubArray(int[] nums) {
int pre = 0, maxAns = nums[0];
for (int x : nums) {
pre = Math.max(pre + x, x);
maxAns = Math.max(maxAns, pre);
}
return maxAns;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String s = scanner.nextLine();
String[] split = s.split(",");
int[] nums = new int[split.length];
for (int i = 0; i<split.length; i++) {
nums[i] = Integer.parseInt(split[i]);
}
System.out.println(maxSubArray(nums));
}
}
Description
给定一个非负整数数组 nums ,你最初位于数组的第一个下标 。
数组中的每个元素代表你在该位置可以跳跃的最大长度。
判断你是否能够到达最后一个下标。
Input
输入一行包含一个字符串,非负整数数组 nums。
1 ≤ nums.length ≤ 3 * 104
0 ≤ nums[i] ≤ 105
Output
能够到达最后一个下标输出true,否则输出false.
Samplem Input 1
2,3,1,1,4
Samplem Ouput 1
true
Samplem Input 1
3,2,1,0,4
Samplem Ouput 1
false
Tip
例1:可以先跳 1 步,从下标 0 到达下标 1, 然后再从下标 1 跳 3 步到达最后一个下标。
例2:无论怎样,总会到达下标为 3 的位置。但该下标的最大跳跃长度是 0 , 所以永远不可能到达最后一个下标。
题目来源:55. 跳跃游戏 - 力扣(LeetCode) (leetcode-cn.com)
题解
package org.example;
import java.util.Scanner;
/**
* @author mumuwei
* @date 2022/4/24
*/
public class PE {
public static boolean canJump(int[] nums) {
int n = nums.length;
int rightmost = 0;
for (int i = 0; i < n; ++i) {
if (i <= rightmost) {
rightmost = Math.max(rightmost, i + nums[i]);
if (rightmost >= n - 1) {
return true;
}
}
}
return false;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String s = scanner.nextLine();
String[] split = s.split(",");
int[] nums = new int[split.length];
for (int i=0; i< split.length; i++) {
nums[i] = Integer.parseInt(split[i]);
}
System.out.println(canJump(nums));
}
}
Description
邯郸美食以具有邯郸特色的风味小吃居多。有彭城三下锅、峰峰抿节面,磁县胖妮熏鸡、永年广府牌酥鱼、临漳临英熏兔、马头魏记熏兔、广府牌五香酱驴肉、广府牌驴蹄筋、广府牌精制驴八珍、广府牌驴板肠、广平桂月牌缯肘、永年驴油烧饼、南沿村拉面、南沿村羊汤、涉县螺丝饼、涉县金丝小窝头、津津乐一口香水饺、南城饭店合记包子、武安锅盔、馆陶酱包瓜等。
小邯好久没有回到家乡了,最近回来特别想吃家乡菜,于是他想要大厨做一桌邯郸本地菜宴请宾客。小邯购买了一些食材,并且制订了宴会的菜单。但是他并不知道这些食材是否足够,所以希望你写一个程序帮助他。
小邯将会给出每种食材的名称和数量,以及完整的菜单。菜单将包含每种菜品所需的食材及数量。菜单上的每道菜只需制作一次。
Input
第一行给出两个整数 , ,分别代表食材种类和菜品数量。
第二到第 + 1 行,每行一个由小写字母组成的字符串 和一个数字 ,表示这种食材的名称和数量。
接下来 行,每行首先有一个整数 ,代表这种菜品所需的食材种类数。
随后将会有 个字符串,代表食材名称,每个字符串后跟有一个数字 ,用空格隔开,代表需要的食材数量。
1 ≤ , ≤ 1000,1 ≤ ≤ 10 且 ≤
1 ≤ , ≤ 109,1 ≤ || ≤ 20
保证输入合法,食材名称不会相同,且菜谱中不会有未出现的食材。
Output
如果食材足够将菜单上的所有菜品全部制作一遍,请输出一行 “YES”,并且按照输入顺序输出剩下的食材以及对应的数量,每行一个食材,用空格将食材和其数量隔开。如果某种食材全部被用完,则不输出该食材。
如果不能,输出一行 “NO”。
Samplem Input
5 3
water 100
flour 20
cabbage 71
pork 12
bean 5
2 water 20 flour 5
3 water 70 cabbage 54 pork 10
5 water 1 flour 1 cabbage 1 pork 2 bean 1
Samplem Ouput
YES
water 9
flour 14
cabbage 16
bean 4
题目来源:第三届河北省大学生程序设计竞赛 Problem K. 河北美食
题解
package org.example;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
/**
* @author mumuwei
* @date 2022/4/25
*/
public class PF {
static Scanner sc = new Scanner(System.in);
public static boolean fun(Map<String, Integer> data) {
int n =sc.nextInt();
for (int i = 0;i<n;i++) {
String name = sc.next();
int num = sc.nextInt();
int remain = data.get(name);
if(remain-num>=0) {
data.put(name, remain-num);
} else {
return false;
}
}
return true;
}
public static void main(String[] args) {
boolean flag = false;
int n = sc.nextInt();
int m = sc.nextInt();
Map<String, Integer> data = new HashMap<>(n);
ArrayList<String> list = new ArrayList<>();
for (int i=0;i<n;i++) {
String name = sc.next();
data.put(name, sc.nextInt());
list.add(name);
}
for (int i=0;i<m;i++) {
if(!fun(data)){
flag = true;
break;
}
}
if(flag){
System.out.println("NO");
} else {
System.out.println("YES");
for (int i =0; i< list.size();i++) {
Integer num = data.get(list.get(i));
if(num>0) {
System.out.println(list.get(i) + " " + num);
}
}
}
}
}
Description
相信大家日常使用手机一定会使用拼音输入法吧,当我们使用拼音九键输入时,是不是会有一些神奇的组合,前几年网上流行着各种九件数字表白大全。
今天我们也用拼音九键来做一个有趣的组合。按照规则给定一个只包含数字 2-9 的字符串,返回所有它能表示的字母组合。答案按字母表顺序返回。给出数字到字母的映射如下拼音九键输入法所示。注意 1 不对应任何字母。
Input
输入一行包含一个字符串str(0 ≤ str.length ≤ 4)。str的每个字符只能是[‘2’, ‘9’] 的一个数字。
Output
按照字母表顺序输出,若首位字母相同,比较次位字母顺序,若次为也相同,比较下一位,以此类推。输出所有的字母组合,用英文逗号隔开。
Samplem Input
23
Samplem Ouput
AD,AE,AF,BD,BE,BF,CD,CE,CF
Tip
注意输入字符串长度!
题目来源:17. 电话号码的字母组合 - 力扣(LeetCode) (leetcode-cn.com)
题解
package org.example;
import java.util.*;
/**
* @author mumuwei
* @date 2022/4/24
*/
public class PG {
public static int INDEX = 0;
public static void letterCombinations(String digits) {
if (digits.length() == 0) {
System.out.println();
}
Map<Character, String> phoneMap = new HashMap<Character, String>() {{
put('2', "ABC");
put('3', "DEF");
put('4', "GHI");
put('5', "JKL");
put('6', "MON");
put('7', "PQRS");
put('8', "TUV");
put('9', "WXYZ");
}};
backtrack(phoneMap, digits, 0, new StringBuffer());
}
public static void backtrack(Map<Character, String> phoneMap, String digits, int index, StringBuffer combination) {
if (index == digits.length()) {
if(INDEX==0) {
System.out.print(combination.toString());
INDEX++;
} else {
System.out.print("," + combination.toString());
}
} else {
char digit = digits.charAt(index);
String letters = phoneMap.get(digit);
int lettersCount = letters.length();
for (int i = 0; i < lettersCount; i++) {
combination.append(letters.charAt(i));
backtrack(phoneMap, digits, index + 1, combination);
combination.deleteCharAt(index);
}
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String s = scanner.nextLine();
letterCombinations(s);
}
}
Description
给定一场ACM 比赛的题目数量和提交列表,请你输出终榜。
榜单的格式见输出和样例
根据比赛规则,榜单有以下要求:
4
00:01 B Wrong Answer University of Deep Dark Fantasy
00:01 B Accepted University of Deep Dark Fantasy
00:01 C Accepted University of Deep Dark Fantasy
00:01 D Accepted University of Deep Dark Fantasy
00:11 A Accepted Deep Dark Institude of Fantasy
00:13 C Wrong Answer Banana University
01:01 C Wrong Answer Banana University
01:11 C Wrong Answer Banana University
02:01 C Runtime Error Deep Dark Institude of Fantasy
02:10 C Accepted Deep Dark Institude of Fantasy
02:30 A Accepted University of Deep Dark Fantasy
02:50 D Accepted Bon Sha Ka La Ka Higher School of Economics
02:51 C Accepted Bon Sha Ka La Ka Higher School of Economics
02:52 B Accepted Bon Sha Ka La Ka Higher School of Economics
02:53 A Accepted Bon Sha Ka La Ka Higher School of Economics
02:55 A Runtime Error University Van Billy
02:59 B Compile Error University Van Banana
GAME OVER!
Samplem Ouput
Rank Who Solved Penalty A B C D
1 University of Deep Dark Fantasy 4 173 + +1 + +
2 Bon Sha Ka La Ka Higher School of Economics 4 686 + + + +
3 Deep Dark Institude of Fantasy 2 161 + +1
4 Banana University 0 0 -3
4 University Van Billy 0 0 -1
题目来源:第三届河北省大学生程序设计竞赛 Problem D. 榜单
题解
#include
using namespace std;
set<string> st = {
"Accepted", "Wrong Answer", "Time Limit Exceeded",
"Compile Error", "Memory Limit Exceeded", "Output Limit Exceeded",
"Runtime Error", "Presentation Error" };
map<string, int> school;
int n, m, mxname;
struct school {
string name;
int pen, num;
int fa[20];
bool guo[20];
bool operator<(const school &rhs) const {
return num == rhs.num
? (pen == rhs.pen ? name < rhs.name : pen < rhs.pen)
: num > rhs.num;
}
} team[3000];
void deal(string s) {
stringstream in(s);
string state, name;
string tmp;
int hour, minute;
char tt;
in >> hour >> tt >> minute >> tmp;
int id = tmp[0] - 'A';
in >> state;
while (st.find(state) == st.end()) {
in >> tmp;
state += " " + tmp;
}
in >> name;
while (in >> tmp) {
name += " " + tmp;
}
if (state[0] == 'C') {
return;
}
if (school.find(name) == school.end()) {
school[name] = ++m;
memset(team[m].guo, 0, sizeof(team[m].guo));
memset(team[m].fa, 0, sizeof(team[m].fa));
team[m].name = name;
mxname = max(mxname, static_cast<int>(name.length()));
}
int tid = school[name];
if (team[tid].guo[id]) {
return;
}
if (state[0] == 'A') {
++team[tid].num;
team[tid].guo[id] = 1;
team[tid].pen += hour * 60 + minute + 20 * team[tid].fa[id];
} else {
++team[tid].fa[id];
}
}
void write() {
sort(team + 1, team + 1 + m);
printf("%4s %-*s %6s %7s", "Rank", mxname, "Who", "Solved", "Penalty");
for (int i = 0; i < n; i++) {
char ts[] = "A";
ts[0] += i;
printf(" %3s", ts);
}
printf("\n");
int rk = 1;
for (int i = 1; i <= m; i++) {
printf("%4d %*s %6d %7d", rk, mxname, team[i].name.c_str(),
team[i].num, team[i].pen);
for (int j = 0; j < n; j++) {
string tmp = "";
if (team[i].guo[j]) {
tmp += "+";
if (team[i].fa[j]) {
char wa[] = "0";
wa[0] += team[i].fa[j];
tmp += wa;
}
} else if (team[i].fa[j]) {
tmp += "-";
char wa[] = "0";
wa[0] += team[i].fa[j];
tmp += wa;
}
printf(" %3s", tmp.c_str());
}
printf("\n");
if (i < m) {
if (team[i].num != team[i + 1].num || team[i].pen != team[i + 1].pen) {
rk++;
}
}
}
}
int main() {
string line;
getline(cin, line);
stringstream in(line);
in >> n;
while (getline(cin, line)) {
if (line.compare("GAME OVER!") == 0) {
write();
break;
} else {
deal(line);
}
}
return 0;
}