首页 > 其他分享 >SMU Winter 2023 Round #6 (Div.2)

SMU Winter 2023 Round #6 (Div.2)

时间:2023-01-20 21:11:47浏览次数:165  
标签:count arr Winter int SMU arr1 Div.2 new scanner

A.OP

题目:

现在请你喊出某次神秘活动中的口号"fengqibisheng, yingyueerlai!"(不包含引号)。

思路:

这道题输出这句话就行

B.Add 9 Zeros

题目:

题意就是将数组A中的数加9后拿到B中,要求加9后在A数组中不存在。

思路:

排序后用双指针扫描,判断两个数的差值是不是7。注意要优化一下,那种两个数的差已经大于9了就不要再往后扫描了。

代码:

点击查看代码
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n;i++) {
			arr[i] = scanner.nextInt();
		}
		Arrays.sort(arr);
		int count = n;
		for(int i = 0;i < n;i++) {
			if(arr[i]+9>arr[n-1]) {//非常关键
				break;
			}
			for(int j = i+1;j < n;j++) {
				if(arr[j]-arr[i]>9) {
					break;
				}
				if(arr[j]-arr[i]==9) {
					count--;
					break;
				}
			}
		}
		System.out.println(count);
	}
}

C.Simple Game

题目:

题意:输入几个数,单个数Alice来加,双个数Bob来加,看他们的和是奇数还是偶数

思路:

首先加起来,然后判断即可

代码:

用java写会超时,同样的思路用C++写不会超时。
点击Java查看代码
import java.util.Scanner;
public class MainJ {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int S1 = 0;
		int S2 = 0;
		for(int i = 1;i<n+1;i++) {
			if(i%2==1) {
				S1+=scanner.nextInt();
			}else {
				S2+=scanner.nextInt();
			}
		}
		if(Math.abs(S1-S2)%2==0) {
			System.out.println("Bob");
		}else {
			System.out.println("Alice");
		}
	}
}

点击C++查看代码
#include<cstdio>
#include<iostream>
#include <algorithm>

using namespace std;

const int N = 1000010;

int n;
int q[N];

int main(){
    int s1,s2;
    scanf("%d",&n);
    for(int i = 1;i<n+1;i++) {
        if(i%2==1) {
            scanf("%d",&q[i]);
            s1+=q[i];
        }else {
            scanf("%d",&q[i]);
            s2+=q[i];
        }
    }
    if(abs(s1-s2)%2!=0){
        printf("Bob");
    }else{
        printf("Alice");
    }
    return 0;
}

D.Elden Ring

题目:

题意:两个长度相同的数组,到报数是两个m的倍数的时候,两个数组的当前值交换。

思路:

代码:

点击查看代码
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		int k = scanner.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		a[0] = n;
		b[0] = 2*n;
		for(int i = 1;i < n;i++) {
			a[i] = i;
			b[i] = n+i;
		}
		int j = 0;
		for(int i = 1;i <= k;i++) {
			if(i%m==0) {
				j = i%n;
				int temp = a[j];
				a[j] = b[j];
				b[j] = temp;
			}
		}
		for(int i = 1;i < n;i++) {
			System.out.print(a[i]+" ");
		}
		System.out.print(a[0]+" ");
		for(int i = 1;i < n;i++) {
			System.out.print(b[i]+" ");
		}
		System.out.print(b[0]+" ");
	}
}

E.Steel of Heart

思路:

这道题按照题目给的思路来,我的做法是把没有用的操作都先去掉,然后再来计算。

代码:

点击查看代码
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int h1 = scanner.nextInt();
		int h2 = scanner.nextInt();
		int m = scanner.nextInt();
		String[] str = new String[m];
		String[] str1 = new String[m];
 		int[] arr = new int[m];
		int[] arr1 = new int[m];
		int[] arr2 = new int[m];
		boolean[] coolingone = new boolean[6];
		for(int i = 0 ;i < m;i++) {
			str[i] = scanner.next();
			arr[i] = scanner.nextInt();
			if(arr[i] == 3) {
				arr1[i] = scanner.nextInt();
			}
		}
		int[] beforemm = new int[6];
		int[] beforess = new int[6];
		int mm = 0;
		int count = 0;
		int ss = 0;
		boolean flag = false;
		for(int i = 0;i < m;i++) {
			if(arr[i] == 1) {
				str1[count] = str[i];
				arr2[count] = arr[i];
				count++;
				flag = true;
			}
			if(arr[i]==2) {
				str1[count] = str[i];
				arr2[count] = arr[i];
				count++;
			}
			if(arr[i] == 3&&flag) {
				mm = Integer.parseInt(""+str[i].charAt(0)+str[i].charAt(1));
				ss = Integer.parseInt(""+str[i].charAt(3)+str[i].charAt(4));
				if(!coolingone[arr1[i]]) {
					str1[count] = str[i];
					arr2[count] = arr[i];
					count++;
					beforess[arr1[i]] = ss+30;
					beforemm[arr1[i]] = mm;
					if(beforess[arr1[i]]>=60) {
						beforemm[arr1[i]] = mm+1;
						beforess[arr1[i]] -= 60;
					}
					coolingone[arr1[i]] = true;
				}else {
					if(mm<beforemm[arr1[i]]||(mm==beforemm[arr1[i]]&&ss<beforess[arr1[i]])) {
						break;
					}else {
						str1[count] = str[i];
						arr2[count] = arr[i];
						count++;
						beforess[arr1[i]] = ss+30;
						beforemm[arr1[i]] = mm;
						if(beforess[arr1[i]]>=60) {
							beforemm[arr1[i]] = mm+1;
							beforess[arr1[i]] -= 60;
						}
						coolingone[arr1[i]] = true;
					}
				}
			}
		}
		for(int i = 0;i < count;i++) {
			if(arr2[i]==1) {
				h1+=800;
			}else if(arr2[i]==2) {
				h1+=h2;
			}else if(arr2[i]==3) {
				h1+=(h1*0.06+125)*0.1;
			}
		}
		System.out.println(h1);
	}
}

标签:count,arr,Winter,int,SMU,arr1,Div.2,new,scanner
From: https://www.cnblogs.com/Tcoo/p/17063213.html

相关文章

  • SMU Winter 2023 Round #7 (Div.2)
    A.解开束缚缠丝II题意:在一堆字符里面找出最长的回文串,并把它的长度输出出来。思路:这道题,一开始想的是把所有情况都列举出来,然后一一判断是不是回文串。后面根据第二个......
  • SMU冬训营第三周周一
    A.Lucky?题意:给出一个六位数,如果它的前三位之和等于它的后三位之和,就输出"YES",否则输出"NO"。思路:测试样例里面有的六位数不是真正的六位数,有的是‘0’开头的,所以选择......
  • 2023WinterHoliday刷题总结第一弹
    \(2023WinterHoliday\)刷题总结第一弹\(CTF\)\(Web\)1.\(json格式:\)$json['x']=="wllm"\(JSON\)(JavaScriptObjectNotation,JS对象简谱)是一种轻量级的数据交换格式,采......
  • Codeforces Round #844 (Div.1 + Div.2) CF 1782 A~F 题解
    点我看题A.ParallelProjection我们其实是要在这个矩形的边界上找一个点(x,y),使得(a,b)到(x,y)的曼哈顿距离和(f,g)到(x,y)的曼哈顿距离之和最小,求出最小值之后加h就是......
  • Codeforces Round #844 (Div.1 + Div.2) CF 1782 A~F 题解
    点我看题A.ParallelProjection我们其实是要在这个矩形的边界上找一个点(x,y),使得(a,b)到(x,y)的曼哈顿距离和(f,g)到(x,y)的曼哈顿距离之和最小,求出最小值之后加h就是......
  • Codeforces Round #844 (Div.1 + Div.2) CF 1782 A~F 题解
    点我看题A.ParallelProjection我们其实是要在这个矩形的边界上找一个点(x,y),使得(a,b)到(x,y)的曼哈顿距离和(f,g)到(x,y)的曼哈顿距离之和最小,求出最小值之后加h就是......
  • SMU冬训营第二周蓝桥杯模拟赛
    A.解码题目:小明有一串很长的英文字母,可能包含大写和小写。在这串字母中,有很多连续的是重复的。小明想了一个办法将这串字母表达得更短:将连续的几个相同字母写成字母+......
  • SMU Winter 2023 Round #3 (Div.2)
    B.三元组题目:给定一个长度为n的数列a,对于一个有序整数三元组(i,j,k),若其满足1≤i≤j≤k≤n并且ai+aj=ak,则我们称这个三元组是「传智的」。现在请你计算,有......
  • SMU Winter 2023 Round #4
    A.Chuanpai题目:Chuanpai(川牌)isakindoftraditionalplayingcardsinSichuan.Eachcardismarkedwithtwointegersxandywhere1≤x≤y≤6.Somesa......
  • Namomo Winter Camp 2023 Day 2
    A-MixJuice排个序再求和就好#include<bits/stdc++.h>usingnamespacestd;intread(){...}int32_tmain(){intn=read(),k=read();vector<int>......