首页 > 其他分享 >SMU Winter 2023 Round #4

SMU Winter 2023 Round #4

时间:2023-01-15 18:55:28浏览次数:56  
标签:count Scanner int SMU nextInt integer Winter Round scanner

A.Chuanpai

题目:

Chuanpai(川牌) is a kind of traditional playing cards in Sichuan. Each card is marked with two integers
x and y where 1 ≤ x ≤ y ≤ 6.
Some samples of Chuanpai.
The first one is marked with 3 and 4, while the second one is marked with 2 and 5.
Given an integer k, please count the number of different types of cards satisfying x + y = k.
We say two cards with integers x1, y1 and x2, y2 are of different types if x1 6= y1 or x2 6= y2.
Input
There are multiple test cases. The first line of the input contains an integer T (1 ≤ T ≤ 100) indicating
the number of test cases. For each test case:
The first and only line contains an integer k (1 ≤ k ≤ 100).
Output
For each test case output one line containing one integer, indicating the number of types of cards satisfying
x + y = k.

题意:
川牌上有两个数,他们属于是1到6的。给出一个数k,求满足条件1 ≤ x ≤ y ≤ 6且x + y = k 的牌有多少种。

思路:

这道题先判断一下k,k大于12的话就没有满足条件的x,y了。然后在一个一个判断就行,满足条件计数器就加一。

代码:

点击查看代码
import java.util.Scanner;
public class MainA {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int count;
		for(int i = 0;i < n;i++) {
			int k = scanner.nextInt();
			count = 0;
			if(k>12) {
				System.out.println(count);
				continue;
			}
			for(int x = 1;x <= 6;x++) {
				for(int y = x;y <= 6;y++) {
					if(x+y==k) {
						count++;
					}
				}
			}
			System.out.println(count);
		}
	}
}

K.K-skip Permutation

题目:

For a permutation P=p1,p2,⋯,pn of n, let f(P,k) be the number of i satisfying 1≤i<n and pi+k=pi+1.

Given two integers n and k, your task is to find a permutation P of n such that f(P,k) is maximized.

Recall that in a permutation of n, each integer from 1 to n (both inclusive) appears exactly once.

题意:

就是给一个范围n和等差d,这个范围内的每个数都要出现一次,求其中最长的那个,如果有多个,找到其中一个就行。

思路:

这个题就是求一个最长的等差数列。如果k是奇数的话,我们每次加上k并取模,这样的话n个数就更好能够取完且不重复。但是如果k是偶数,就取不到n个了,只能取n/k个了。但是最后一个测试只有用C++写才能过,其他语言我都过不了。

代码:

点击查看java代码
import java.util.Scanner;
public class MainK_1 {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int k = scanner.nextInt();
		for(int i  = 1;i <= k;i++) {
			for(int j = i;j <= n;j += k) {
				System.out.println(j+" ");
			}
		}
	}
}
点击C++查看代码
#include <iostream>
using namespace std;
int main() {
    int n,k;
    cin >> n >> k;
    for(int i = 1; i <= k;i++){
        for(int j = i;j <= n;j += k ){
            cout << j << ' ';
        }
    }
    return 0;
}

标签:count,Scanner,int,SMU,nextInt,integer,Winter,Round,scanner
From: https://www.cnblogs.com/Tcoo/p/17053798.html

相关文章

  • Educational Codeforces Round 119 (Rated for Div. 2)
    EducationalCodeforcesRound119(RatedforDiv.2)我真是越来越菜了,现在竟然连a都做不出来了,o(╥﹏╥)oAA这个题是对于每一个ai和ai+1,(an和a1)都有一个判断,判断这两......
  • Codeforces Round #843 (Div. 2)
    C.InterestingSequence(二进制)题目大意给定两个大于等于0的数\(n,\x\),求满足\(n\&(n+1)\&(n+2)\cdotsm=x\)的最小\(m\),若不存在输出-1。解题思路首先若\(n<x\)肯......
  • Educational Codeforces Round 108 (D记忆化搜索)
    D.MaximumSumofProducts题目大意:给定两个长度为n(n<=5000)的整型数组a,b可以对数组a进行至多一次以下操作:选择l,r并对l到r进行翻转求\(\sum\)a\(_i\)*b\(_i\)的......
  • Codeforces Round #839 F
    F.CopyofaCopyofaCopy题链我们发现这个操作是将中间不一样周围四个一样的形如1010101010变成全部都一样的显然这样变之后是不可还原的就是说这......
  • Codeforces Round #843 (Div. 2) A1A2BCE(D待补)
    url:Dashboard-CodeforcesRound#843(Div.2)-CodeforcesA1&&A2.GardenerandtheCapybaras题意:给你一个只由$a$和$b$两个字符组成的字符串现在要你把这个字......
  • Codeforces Round #834 (Div. 3) D. Make It Round(贪心/数论)
    https://codeforces.com/contest/1759/problem/D题目大意:给定一个数字n,要求扩大至多m倍,求最大的并且最多0的数字。input106115431354161005012345264......
  • Educational Codeforces Round 110 C(最长连续字串,dp),D(左右子树继承贡献dp)
    C.UnstableString题目大意:给定一个长度为n的字符串且只包括'0','1','?',其中如果一个字串是由01交替组成的则称谓不稳定的,如果碰到'?'则可以将其转化为0/1,求不稳定的......
  • Codeforces Round #843 (Div. 2) F. Laboratory on Pluto
    题目链接首先看问题一(算最小周长),并没有用题解的神奇结论,而是直接整除分块枚举\((n-1)/x\),取对应的最小x,在\(\sqrtn\)种可能内取最优的(能暴力算为什么要考虑结论呢)然而最......
  • Educational Codeforces Round 13
    EducationalCodeforcesRound13AJohnyLikesNumbers做法:假设答案为\(t*k\)考虑$(t-1)*k$,所以答案显然为$n-n$\(\%\)$k+k$代码:voidsolve(){in......
  • Educational Codeforces Round 16
    EducationalCodeforcesRound16https://codeforces.com/contest/7104/6:ABCEA.KingMoves#include<bits/stdc++.h>usingnamespacestd;intcnt,ans;intmain......