A題:
一道dp的題目
dp[i][j] = k 表明 i行放j個棋子有k中可能
dp[i][j] = dp[i-1][0] + dp[i-1][1] + dp[i-1][2] +...dp[i-1][j]
初始 dp[1][0] = 1, dp[1][1] = 1java
注意點:code
import java.util.*; import java.math.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); BigInteger[][] dp = new BigInteger[110][110]; for (int i = 0;i <= 109; i++) for(int j = 0;j <= 109; j++) dp[i][j] = new BigInteger("0"); dp[1][0] = new BigInteger("1"); dp[1][1] = new BigInteger("1"); int n = sc.nextInt(); for (int i = 2; i <= n ;i++){ for (int j = 0; j <= i; j++){ for (int k = 0; k <= j; k++){ dp[i][j] = dp[i][j].add(dp[i-1][k]); } } } BigInteger ans = new BigInteger("0"); for (int i = 1; i <= n; i++) ans = ans.add(dp[n][i]); System.out.println(ans); } }
B題:用公式
不知道這個A的伴隨矩陣公式,就很難受了- - 。。orm
import java.util.*; public class Main2{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for (int i = 0; i < T; i++) { int[][] A = new int[3][3]; for (int m = 0; m < 3; m ++) { for (int n = 0; n < 3; n++) { A[m][n] = sc.nextInt(); } } long ao = (A[0][0]* A[1][1]* A[2][2]) + (A[1][0]* A[2][1]* A[0][2]) + (A[2][0]* A[0][1]* A[1][2]) - (A[0][2]* A[1][1]* A[2][0]) - (A[0][0]* A[1][2]* A[2][1]) - (A[0][1]* A[1][0]* A[2][2]); System.out.println(ao* ao); } } }
C題:
一開始理解錯了,他的意思是a^n,我還覺得要a *=a;get
import java.math.BigInteger; import java.util.*; public class Main3{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for (int i = 0; i < T; i++) { BigInteger a = new BigInteger("0"), n = new BigInteger("0"), b = new BigInteger("0"); a = sc.nextBigInteger(); n = sc.nextBigInteger(); b = sc.nextBigInteger(); System.out.println(a.modPow(n,b)); } } }
E題:
感受巨他媽坑了,原本io
××if (y1_xing == C)
××B --;
我都服了,被這個卡了小半天。。form
import java.math.BigInteger; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; public class Main{ static int y1_xing; static boolean r; static int ny, nm, nd; static int[] monthofday = new int[]{-1,31,28,31,30,31,30,31,31,30,31,30,31}; static int res; //這個月的幾號 public static boolean is_run(int year) { if (year % 400 == 0 ||(year % 4 == 0 && year % 100 != 0)) return true; return false; } public static void gety1_xing(int ny,int y,int A, int B, int C) { y1_xing = 1; for (ny = 1850; ny < y; ny++) { for (nm = 1; nm <= 12; nm ++) { int month_ofday = monthofday[nm]; if(is_run(ny) && nm == 2) month_ofday += 1; for(nd = 1; nd <= month_ofday; nd++) { y1_xing += 1; if (y1_xing == 8) y1_xing = 1; } } } for(nm = 1;nm < A;nm++) { int month_ofday = monthofday[nm]; if(is_run(y) && nm == 2) month_ofday += 1; for(nd = 1; nd <= month_ofday; nd++) { y1_xing += 1; if (y1_xing == 8) y1_xing = 1; } } boolean has = false; int month_ofday = monthofday[nm]; if(is_run(y) && B == 2) month_ofday += 1; for (res = 1;res <= month_ofday; res++) { y1_xing += 1; if (y1_xing == 8) { y1_xing = 1; } if (y1_xing == C) B --; if (B == 0) { has = true; break; } } if(!has) res = -1; } public static void main(String[] args) throws ParseException{ Scanner sc = new Scanner(System.in); while (sc.hasNextInt()) { int A = sc.nextInt(), B = sc.nextInt(), C = sc.nextInt(), y = sc.nextInt(); gety1_xing(ny,y, A, B, C); if (res != -1) { Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, y); c.set(Calendar.MONTH, A - 1); c.set(Calendar.DAY_OF_MONTH, res); Date d=new Date(); d=c.getTime(); SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd"); String str=sdf.format(d); System.out.println(str); } else System.out.println("none"); } } }
H題:
先打表,在找規律!class
import java.math.BigInteger; import java.util.*; public class MainH{ //打表 -> 找規律! //100 1-1 1-2 1-3 1-4....1-100 //99 1-1 1-2 1-3...1-99 //... //2 1-1 1-2 //1 1-1 public static void main(String[] args){ /* for(int i = 1; i <= 10 ; i++) { int[] a = new int[i + 1]; //計數從1開始 //通過i次 for(int j = 2; j <= i; j++) { for(int k = 1; k*j < a.length; k++) { a[k*j] = 1 - a[k*j]; } } for (int j = 1; j <= i; j++) { System.out.print(a[j]+" "); } System.out.println(); }*/ //找到規律:規律是: //通過i次,爲1的位置爲:1 4 9 16 25 36 49 64 81 100 121 144 // A=1,B=3 //4 - 1 - 1 = 2, 9 - 4 - 1 =4, //16 - 9 - 1 = 6, 25 - 16 - 1 = 8 //依次增加2 //1: 0 0 0 0 0 //2: 0 1 0 1 0 //3: 0 1 1 1 0 //4: 0 1 1 0 0 //5: 0 1 1 0 1 Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for (int i = 0; i < T; i++) { long N = sc.nextLong(), A = sc.nextLong(),B = sc.nextLong(); int start = 1; int gap = 2; while (start < A) { start += gap + 1; gap += 2; } //start >= A int res = 0; while (start <= B) { res ++; start += gap + 1; gap += 2; } System.out.println(B - A+1-res); } } }
感受沒有練習過ACM 的確是作得磕磕拌拌,全是坑!!! 明天接着更剩下的題吧- - 。。import