蓝桥杯java省赛第三题
第十一届2020-3蛇形填空(10分)
答案: 761
public static void main(String[] args) {
// 斜对角
int a = 1;
for (int i = 0; i < 20; i++) {
a = a + (i * 4);
System.out.println(a);
}
}
第十届2019-3数列求值(10分)
答案:4659
public static void main(String[] args) {
int a = 1, b = 1, c = 1;
// 要是求第四项,则i < 4, 同理推得求20190324,则i < 20190324。
for (int i = 3; i < 20190324; i++) {
int temp = (a + b + c) % 10000;
a = b;
b = c;
c = temp;
}
System.out.println(c);
}
第九届2018-3复数幂(10分)
public class c2018 {
public static void main(String[] args) throws FileNotFoundException {
BigInteger two= BigInteger.valueOf(2);
BigInteger three= BigInteger.valueOf(3);
BigInteger a= BigInteger.valueOf(2);
BigInteger b= BigInteger.valueOf(3);
BigInteger aa=null;
BigInteger bb=null;
//(2+3i)(a+bi)=(2a-3b)(2b+3a)i
for(int i=0;i<123456;i++){
aa=a.multiply(two).subtract(b.multiply(three));
bb=b.multiply(two).add(a.multiply(three));
a=aa;
b=bb;
}
// System.out.println(new PrintStream(new File("D:\\outc.txt")));
// System.out.println(aa+(bb.compareTo(BigInteger.ZERO)<0?"-":"+")+bb+"i");
PrintStream ps1=new PrintStream(new FileOutputStream(new
File("D:\\outc.txt")));
ps1.println(aa+(bb.compareTo(BigInteger.ZERO)<0?"-":"+")+bb+"i");
}
}
第九届2017-3承压计算(10分)
public class c2017 {
static long[][] arr=new long [30][30];
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
long factor=1;
//2的30次方
for (int i = 0; i < 30; i++) {
factor<<=1;
}
//输入数据放入二维数组
for (int i = 0; i < 29; i++) {
for (int j = 0; j <=i; j++) {//<=!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
long a=sc.nextLong();
arr[i][j]=a*factor;//每个数据都乘以factor
}
}//自上而下处理a[i][j]*factor(2的30次方)-->除以2,计入a[i+1][j+1]//循环处理第1~N-1行
for (int i = 0; i < 29; i++) {
for (int j = 0; j <= i; j++) {
long ha=arr[i][j]/2;
arr[i+1][j]+=ha;
arr[i+1][j+1]+=ha;
}
}//对a[N-1]这一行进行排序,查看最小值与factor之间的倍数关系,决定最大值是多少
Arrays.sort(arr[29]);
System.out.println(arr[29][0]);
System.out.println(arr[29][29]);
System.out.println(arr[29][29]/(arr[29][0]/2086458231));
}
}
第九届2016-3凑算式(10分)
public class c2016 {
static int a[]={1,2,3,4,5,6,7,8,9};
static int ans;
static boolean check(){
int x=a[3]*100+a[4]*10+a[5];
int y=a[6]*100+a[7]*10+a[8];
if((a[1]*y+a[2]*x)%(y*a[2])==0&&a[0]+(a[1]*y+a[2]*x)/(y*a[2])==10)
return true;
return false;
}
static void f(int k){
if(k==9){
if(check()){
ans++;
}}
for(int i=k;i<9;i++){
int t=a[i];
a[i]=a[k];
a[k]=t;
f(k+1);
{
int tt=a[i];
a[i]=a[k];
a[k]=tt;
}
}
}
public static void main(String[] args) {
f(0);
System.out.println(ans);
}
}