2018年12月,提交满分代码
问题描述
试题编号: | 201812-1 |
试题名称: | 小明上学 |
时间限制: | 1.0s |
内存限制: | 512.0MB |
问题描述: | 题目背景 小明是汉东省政法大学附属中学的一名学生,他每天都要骑自行车往返于家和学校。为了能尽可能充足地睡眠,他希望能够预计自己上学所需要的时间。他上学需要经过数段道路,相邻两段道路之间设有至多一盏红绿灯。 问题描述 一次上学的路上,小明记录下了经过每段路的时间,和各个红绿灯在小明到达路口时的颜色和倒计时秒数。希望你帮忙计算此次小明上学所用的时间。 输入格式 输入的第一行包含空格分隔的三个正整数 r、y、g,表示红绿灯的设置。这三个数均不超过 106。 输出格式 输出一个数字,表示此次小明上学所用的时间。 样例输入 30 3 30 样例输出 70 样例说明 小明先经过第一段道路,用时 10 秒,然后等待 5 秒的红灯,再经过第二段道路,用时 11 秒,然后等待 2 秒的黄灯和 30 秒的红灯,再经过第三段、第四段道路,分别用时6、3秒,然后通过绿灯,再经过最后一段道路,用时 3 秒。共计 10 + 5 + 11 + 2 + 30 + 6 + 3 + 3=70 秒。 评测用例规模与约定 测试点 1, 2 中不存在任何信号灯。 |
package com.hsx.ccf;
import java.util.Scanner;
public class Ccf20181201 {
public static void main(String[] args) {
@SuppressWarnings("resource")
Scanner scanner = new Scanner(System.in);
int r = scanner.nextInt();
int y = scanner.nextInt();
int g = scanner.nextInt();
int n = scanner.nextInt();
int time = 0;
for(int i = 0; i < n; i++){
int k = scanner.nextInt();
int t = scanner.nextInt();
if(k != 3){
time += t;
}
if(k == 2){
time += r;
}
}
System.out.println(time);
}
}
2018年9月,提交满分代码
试题编号: | 201809-1 |
试题名称: | 卖菜 |
时间限制: | 1.0s |
内存限制: | 256.0MB |
问题描述: | 问题描述 在一条街上有n个卖菜的商店,按1至n的顺序排成一排,这些商店都卖一种蔬菜。 输入格式 输入的第一行包含一个整数n,表示商店的数量。 输出格式 输出一行,包含n个正整数,依次表示每个商店第二天的菜价。 样例输入 8 样例输出 2 2 1 3 4 9 10 13 数据规模和约定 对于所有评测用例,2 ≤ n ≤ 1000,第一天每个商店的菜价为不超过10000的正整数。 |
package com.hsx.ccf;
import java.util.Scanner;
public class Ccf20180901 {
public static void main(String[] args) {
@SuppressWarnings("resource")
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int []a = new int[1001];
for(int i = 0; i < n; i++){
a[i] = scanner.nextInt();
}
int price1 = (a[0]+a[1])/2;
System.out.print(price1+" ");
for(int i = 1; i < n-1; i++){
int price = (a[i]+a[i-1]+a[i+1])/3;
System.out.print(price+" ");
}
int price2 = (a[n-2]+a[n-1])/2;
System.out.println(price2+" ");
}
}
2018年3月,提交满分代码
试题编号: | 201803-1 |
试题名称: | 跳一跳 |
时间限制: | 1.0s |
内存限制: | 256.0MB |
问题描述: | 问题描述 近来,跳一跳这款小游戏风靡全国,受到不少玩家的喜爱。 输入格式 输入包含多个数字,用空格分隔,每个数字都是1,2,0之一,1表示此次跳跃跳到了方块上但是没有跳到中心,2表示此次跳跃跳到了方块上并且跳到了方块中心,0表示此次跳跃没有跳到方块上(此时游戏结束)。 输出格式 输出一个整数,为本局游戏的得分(在本题的规则下)。 样例输入 1 1 2 2 2 1 1 2 2 0 样例输出 22 数据规模和约定 对于所有评测用例,输入的数字不超过30个,保证0正好出现一次且为最后一个数字。 |
package com.hsx.ccf;
import java.util.Scanner;
public class Ccf20180301 {
public static void main(String[] args) {
@SuppressWarnings("resource")
Scanner scanner = new Scanner(System.in);
int sore = 0;
int num = 0;
int a = 0;
while((a = scanner.nextInt()) != 0){
if(a == 1){
sore += a;
num = 0;
}else if(a == 2){
sore += 2*(++num);
}
}
System.out.println(sore);
}
}