2020/4/11---ACM初赛---牛客网---

2020/4/11---ACM初赛---牛客网---_第1张图片
输入

2 10
8 5

输出

3
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int[] h = new int[a];
        long s = 1L;//加L
       if ((a >= 2 && a <= 2 * 1e5) && (b >= 1 && b <= 1000)){
            for (int i = 0; i < a; i++) {
                h[i] = sc.nextInt();
            }
            for (int i = 0; i <a; i++) {
                for(int j=i+1;j<a;j++){
                    s = s*Math.abs(h[i] - h[j])%b;//取模
                }
            }
        }
        System.out.println(s);
    }
}

Giant pandas like to eat bamboo most. Now there are M bamboo in the zoo. Their lengths are S1, S2 SN. There are N pandas in the zoo. As an employee, you need to cut the bamboo and distribute it evenly on each panda.A panda can only get a section of bamboo. You need to cut the bamboo into N segments of the same length. What is the maximum length of each section of bamboo? (Keep the answer to two decimal places)

Limit:

1≤M≤10000

1≤N≤10000

1≤Si≤100000
输入描述:
Number of Bamboo

Number of pandas

Length of each section of bamboo

输出描述:
the maximum length of each section ofbamboo(Keep two decimal places)
示例1:

4
11
8.02 7.43 4.57 5.39
2.00

将8.02分割为4个2.00的,7.43分割为3个2.00的,4.57分割为2个2.00的,5.39分割为2个2.00的,共11个,一只熊猫一个2.00的(考虑二分加速)

import java.util.Arrays;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int n = sc.nextInt();
        double[] a = new double[m];
        double sum = 0, re;
        for (int i = 0; i < m; i++) {
            a[i] = sc.nextDouble();
            sum += a[i];
        }
        Arrays.sort(a);
        re = (double) Math.round((sum * 100) / n) / 100;
        double l = 0, r = re;
        do{
            int t = 0;
            for (int i = 0; i < m; i++) {
                t += (int) (a[i] / re);
            }
            if (t < n) {
                r = re;
            } else if (t >= n) {
                l = re;
            }
            re = (r + l) / 2;
        }while(r-l>0.01);
        System.out.printf("%.2f",l);
    }
}

给出一个数,请你将它分解为两个数的乘积,不能是1和他本身
输入描述:
在这里插入图片描述
输出描述:
输出两个数 a,b 使得a*b=n
示例1
输入
10
输出
2 5
备注:
a和b都不能为1

2开始枚举任意n的因子,输出因子以及 n/因子即可
标程:
#include
#include
int main()
{
 int i, j, n;
scanf("%d", &n);
for (i=2; i<=sqrt(n); i++)
 {
 if (n%i==0)
 {
 printf("%d %d", i, n/i);
return 0;
 }
 }
}

而我用的Java写的?太庸长,还不好记

import java.util.Scanner;
import static java.lang.System.exit;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (f(n) == false&& (n >= 4) && n <= 1e9) {
            for(int i=2;i<=n-1;i++){
                if(n%i==0){
                    System.out.println(i+" "+n/i);exit(0);
                }
            }
        }
    }
    public static boolean f(int n) {//判断素数,是true 否false
        if (n <= 3) {
            return n > 1;
        }
        if (n % 6 != 1 && n % 6 != 5) {
            return false;
        }
        int sqrt = (int) Math.sqrt(n);
        for (int i = 5; i <= sqrt; i += 6) {
            if (n % i == 0 || n % (i + 2) == 0) {
                return false;
            }
        }
        return true;
    }
}

兰大有善口技者,名曰GJX,能颂红鲤鱼与绿鲤鱼与驴。你若说1,他便回hongliyu,你若说2,他便回lvliyu,你若说3,他便回lv。现在,你说出了一串只包含1、2、3的数字,请你告诉我们,GJX回答了什么?

输入描述:
一行,一个由数字组成的字符串。
输出描述:
一行,一个字符串,代表GJX的回答。
示例1
输入
123123
输出
hongliyulvliyulvhongliyulvliyulv
备注:
输入字符串长度<=100

#include
int main()
{//最短时间1m
    int i;
    char nub[100];
    gets(nub);
    for(i=0;i<100;i++)
    {
        if(nub[i]=='1')
            printf("hongliyu");
                    else if(nub[i]=='2')
                        printf("lvliyu");
                                else if(nub[i]=='3')
                                    printf("lv");
 
    }
}
#include//同样1m
#include
#define N 100
int main()
{
    char str[N];
    gets(str);
    int n;
    for(n=0;str[n]!='\0';n++)
    {
        if(str[n]=='1')
        {
            printf("hongliyu");
        }
        else if(str[n]=='2')
        {
            printf("lvliyu");
        }
        else if(str[n]=='3')
        {
            printf("lv");
        }
    }
    return 0;
}
#include<stdio.h>
int main()
{
int a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d);
if(a<100&&b<100&&c<100&&d<100){
    if((a+b==c+d)||(a+c==b+d)||(a+d==b+c)||
      (a==b+c+d)||(b==a+c+d)||(c==a+b+d)||(d==a+b+c)
      )
        printf("YES");
else printf("NO");
}
  return 0;
}

你可能感兴趣的:(2020/4/11---ACM初赛---牛客网---)