update
出成绩啦 一等 hhh 还不错 组委会没有出现初赛那些糊里糊涂的错误了。(bfs的vis数组都没写也一等,水是真的水啊)
感觉还是挺简单的?刚刚打传智杯去啦,现在来记录下,聚聚们看看菜鸡错了吗
第一题:
(1)这个题可能就是要注意下说如果打了多道主食,要累计一下?全部加起来,最后在进行收费还是不收费的判断,不知道是不是这样呢?
package 决赛;
import java.util.Scanner;
/**
* @author fancy
* @date 2020/12/20 13:16
*/
public class TestA {
static int n;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
double ans = 0;
int sum = 0;
double sump = 0;
while(n-- > 0){
char k = sc.next().charAt(0);
int m = sc.nextInt();
double p = sc.nextDouble();
if(k == 'R'){
sum += m;
sump = p;
}
else{
ans += m/100.0 * p;
}
}
if(sum > 200) ans += sum/100.0 * sump;
double t = sc.nextDouble();
if(t > 0 && t < 0.2) ans = ans-ans*(0.2-t);
System.out.printf("%.2f\n",ans);
}
}
第二题:
(1)直接暴力即可,注意下不要多输出了就行
package 决赛;
import java.util.Scanner;
/**
* @author fancy
* @date 2020/12/20 13:16
*/
public class TestB {
static int a,b;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
a = sc.nextInt();b = sc.nextInt();
int cnt = 0;
while(cnt < 10) {
int c = a * b;
if (c > 9999) {
int x = c % 10000;
int y = c / 10000;
if(cnt == 9){
System.out.println(x);
break;
}
else {
cnt += 2;
if(cnt == 10)
System.out.println(x + " " + y);
else {
a = x;
b = y;
System.out.print(x + " " + y+" ");
}
}
} else {
a = b;
b = c;
cnt++;
if(cnt == 10)
System.out.println(b);
else
System.out.print(b+" ");
}
}
}
}
第三题:
(1)直接用api排序就行,应该没问题吧,qaq
package 决赛;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
/**
* @author fancy
* @date 2020/12/20 13:16
*/
public class TestC {
static int n,k;
static Integer a[] = new Integer[10010];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();k = sc.nextInt();
for(int i = 1;i <= n;i++)
a[i] = sc.nextInt();
Arrays.sort(a,1,k+1);
Arrays.sort(a,k+1,n+1, new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
return o2-o1;
}
});
Arrays.sort(a,1,k-2+1);
Arrays.sort(a,k-2+1,n+1,new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
return o2-o1;
}
});
for(int i = 1;i < n;i++)
System.out.print(a[i]+" ");
System.out.println(a[n]);
}
}
第四题:
(1)用map存每一个node,然后无限循环,到了终点就输出即可。
package 决赛;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
/**
* @author fancy
* @date 2020/12/20 13:16
*/
public class TestD {
static String s;
static Map<String,String> map = new HashMap<String,String>();
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
s = sc.nextLine();
int p = -1;
while(p+7 < s.length()){
p += 2;
String s1 = "";
for(int i = 0;i < 5;i++)
s1 += s.charAt(p+i);
p += 7;
String s2 = "";
for(int i = 0;i < 5;i++)
s2 += s.charAt(p+i);
p += 5;
map.put(s1,s2);
}
String t1,t2;
t1 = sc.next();
t2 = sc.next();
int cnt = 0;
while(true){
if(t1.equals(t2)) break;
t1 = map.get(t1);
cnt++;
}
System.out.println(cnt);
}
}
第五题:
(1)或许写的有点复杂了?把每一个英文标记为一个数字,用map记录这个字符串跟数字的关系,然后建图,bfs扫,我也不知道有没有bug啊 ,嘤嘤嘤
package 决赛;
import java.util.*;
/**
* @author fancy
* @date 2020/12/20 13:17
*/
public class TestE {
static int a[][] = new int[410][410];
static int vis[] = new int[410];
static Map<String,Integer> map = new HashMap<String, Integer>();
static int n,cnt;
static String s,f;
static Queue<Node> q = new LinkedList<Node>();
static void bfs(String x,String y){
int u = map.get(x),v = map.get(y);
vis[u] = 1;
if(u == v){
System.out.println(1);
return;
}
q.add(new Node(u,1));
while(!q.isEmpty()){
Node node = q.poll();
if(node.pos == v){
System.out.println(node.cnt);
return;
}
for(int i = 1;i < cnt;i++){
if(a[node.pos][i] == 1 && vis[i] == 0){
vis[i] = 1; // 比赛的时候忘记写了 我吐了
q.add(new Node(i,node.cnt+1));
}
}
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
s = sc.next(); f = sc.next();
sc.nextLine();
for(int i = 0;i < n;i++){
String k[] = sc.nextLine().split(" ");
for(int j = 0;j < k.length-1;j++){
int x,y;
if(map.containsKey(k[j])) x = map.get(k[j]);
else{
x = ++cnt;
map.put(k[j],x);
}
if(map.containsKey(k[j+1])) y = map.get(k[j+1]);
else{
y = ++cnt;
map.put(k[j+1],y);
}
a[x][y] = 1;
a[y][x] = 1;
}
}
bfs(s,f);
}
}
class Node{
int pos,cnt;
Node(int pos,int cnt){
this.pos = pos;
this.cnt = cnt;
}
}
第六题:
(1)dp 就跟洛谷的小A点菜一模一样哦~
package 决赛;
import java.util.Scanner;
/**
* @author fancy
* @date 2020/12/20 13:17
*/
public class TestF {
static int n,m;
static int a[] = new int[66];
static int dp[][] = new int[1010][1010]; // 前i袋大米 用完j重量的方案数
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
m = sc.nextInt();
for(int i = 1;i <= n;i++) a[i] = sc.nextInt();
for(int i = 1;i <= n;i++)
for(int j = 1;j <= m;j++){
if(j == a[i]) dp[i][j] = dp[i-1][j]+1;
if(j > a[i]) dp[i][j] = dp[i-1][j] + dp[i-1][j-a[i]];
if(j < a[i]) dp[i][j] = dp[i-1][j];
}
System.out.println(dp[n][m]);
}
}
记录下自己的代码,害,看看会有多少分吧~
版权声明:本文为shizhuba原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。