1.斗牛
原题: 给定五个 0~9 范围内的整数 a1, a2, a3, a4, a5。如果能从五个整数中选出三个并且这三个整数的和为10 的倍数(包括 0),那么这五个整数的权值即为剩下两个没被选出来的整数的和对 10 取余的结果,显然如果有多个三元组满⾜和是 10 的倍数,剩下两个数之和对 10 取余的结果都是相同的;
如果选不出这样三个整数,则这五个整数的权值为 -1。
现在给定 T 组数据,每组数据包含五个 0~9 范围内的整数,分别求这 T 组数据中五个整数的权值
【输⼊格式】 第⼀⾏⼀个整数 T (1<=T<=1000),表⽰数据组数。 接下来 T ⾏,每⾏ 5 个 0~9 的整数,表⽰⼀组数据。
【输出格式】输出 T ⾏,每⾏⼀个整数,表⽰每组数据中五个整数的权值。
【样例输⼊】
4
1 0 0 1 0
1 0 0 8 6
3 4 5 6 7
4 5 6 7 8
【样例输出】
2
-1
-1
0
public class Main {
public static void main(String[] args) {
Scanner in =new Scanner(System.in);
int T=in.nextInt();
Dou_niu(T);
}
public static int judgeNum(int[] num){
int result=-1;
for(int x=0;x<=2;x++){
for(int y=x+1;y<=3;y++){
for(int z=y+1;z<=4;z++){
if((num[x]+num[y]+num[z])%10==0){
return (num[0]+num[1]+num[2]+num[3]+num[4]-num[x]-num[y]-num[z])%10;
}
}
}
}
return result;
}
public static void Dou_niu(int T){
//【输⼊格式】 第⼀⾏⼀个整数 T (1<=T<=1000),表⽰数据组数。
// 接下来 T ⾏,每⾏ 5 个 0~9 的整数,表⽰⼀组数据。
//【输出格式】输出 T ⾏,每⾏⼀个整数,表⽰每组数据中五个整数的权值。
Scanner in =new Scanner(System.in);
int[] outPut=new int[T+1];
int[] num=new int[5];
for(int i=0;i<T;i++){
for(int j=0;j<5;j++){
num[j]=in.nextInt();
}
outPut[i]=judgeNum(num);
}
for(int i=0;i<T;i++){
System.out.println(outPut[i]);
}
}
2.打地鼠
原题: 给定 n 个整数 a1, a2, …, an 和⼀个 d,你需要选出若⼲个整数,使得将这些整数从⼩到⼤排好序之后,任意两个相邻的数之差都不⼩于给定的 d,问最多能选多少个数出来。
【输⼊格式】 第⼀⾏两个整数 n,d (1<=n<=10^5, 0<=d<=10^9),分别表⽰整数个数和相邻整数差的下界。 第⼆⾏ n个整数 a1, a2, …, an (1<=ai<=10^9, 1<=i<=n),表⽰给定的 n 个整数。
【输出格式】 仅⼀⾏⼀个整数,表⽰答案。
【样例输⼊】
6 2
1 4 2 8 5 7
【样例输出】
3
public static void beatMouse(){
Scanner in=new Scanner(System.in);
int n=in.nextInt();
int d=in.nextInt();
int[] num=new int[n];
for(int i=0;i<n;i++){
num[i]=in.nextInt();
}
Arrays.sort(num);
int last=num[0];
int count=1;
for(int i=1;i<=n-1;i++){
if((num[i]-last)>=d){
count++;
last=num[i];
}
}
System.out.println(count);
}