2019院程序设计大赛AC的题
ZN发现炸鸡中有n个炸鸡块,编号从1到 n;有 t 包琥珀酱,ZN每次可以选择一 个区间[l, r][l, \ r][l, r],将编号在l到r之间的炸鸡都涂上一层酱。
ZN想从酱最多的炸鸡块开始吃,即被涂次数最多的炸鸡块。你能帮ZN计算一下每块炸鸡都被涂了多少次吗?
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String str = scanner.nextLine();
String[] numList = str.split("\\s");
int n = Integer.parseInt(numList[0]);
int t = Integer.parseInt(numList[1]);
int[] a=new int[n];
for(int i=0;i<t;i++)
{
String s = scanner.nextLine();
String[] num = s.split("\\s");
int l = Integer.parseInt(num[0]);
int r = Integer.parseInt(num[1]);
for(int j=l-1;j<=r-1;j++)
{
a[j]++;
}
}
for(int i=0;i<n;i++){
if(i==n-1){
System.out.print(a[i]);
}else {
System.out.print(a[i] + " ");
}
}
}
}
2.有三种形状的物体,分别是三角形,圆形和正方形,分别都有若干个,其中两个不同形状的物体碰撞在一起就会形成两个第三种形状的物体。Garrett学长觉得三种形状太多了,想把它们变成同一种形状,问题来了,对于不同数量的这三种物体,进行若干次操作,这三种形状的物体最后能不能变成同一种形状呢? 如果可以的话,请输入"YES",如果不可以的话,请输出“NO”
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
long temp,t,a,b,c;
t=sc.nextLong();
while(t>0){
a=sc.nextLong();
b=sc.nextLong();
c=sc.nextLong();
if(a>b){temp=a;a=b;b=temp;}
if(a>c){temp=c;c=a;a=temp;}
if(b>c) {temp=c;c=b;b=temp;}
if(a==b){System.out.println("YES");}
else if(b==c){System.out.println("YES");}
else if((b-a)%3==0||(c-a)%3==0||(c-b)%3==0){System.out.println("YES");}
else{System.out.println("NO");}
t--;
}
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int q;
q=sc.nextInt();
BigInteger l,r;
String a,b;
BigInteger zero=new BigInteger("0");
BigInteger one =new BigInteger("1");
BigInteger two =new BigInteger("2");
BigInteger three =new BigInteger("3");
BigInteger six =new BigInteger("6");
for(int i=0;i<q;i++)
{
a=sc.next();
b=sc.next();
l=new BigInteger(a);
l=l.subtract(one);
r=new BigInteger(b);
BigInteger sum =new BigInteger("0");
BigInteger judge =new BigInteger("1000000007");
l=three.multiply(l.multiply(l.add(one)).multiply(l.multiply(two).add(one)).divide(six)).add(l);
r=three.multiply(r.multiply(r.add(one)).multiply(r.multiply(two).add(one)).divide(six)).add(r);
sum=r.subtract(l);
sum=sum.mod(judge);
System.out.println(sum.toString());
}
}
}