二分题目:
B3880 [信息与未来 2015] 买木头 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.security.PublicKey;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;import javax.naming.directory.SearchControls;public class Main {public static void main(String[] args) throws IOException {Scanner sc=new Scanner(System.in);BufferedReader br1=new BufferedReader(new InputStreamReader(System.in));PrintWriter pw1=new PrintWriter(System.out);
String[] aStrings=br1.readLine().split(" ");
bb=Integer.parseInt(aStrings[0]);
ccnumber=Integer.parseInt(aStrings[1]);
int length=Integer.parseInt(aStrings[2]);
int ss=Integer.parseInt(aStrings[3]);
int a;
aa[0][0]=length;
aa[0][1]=ss;
for(a=1;a<bb;a++) {aa[a][0]=((aa[a-1][0]*37011+10193)%10000)+1;aa[a][1]=((aa[a-1][1]*73011+24793)%100)+1;
}
int left=0;
int right=10002;
int answer=0;
while(left<=right) {int mid=(left+right)>>>1;if(check(mid)==1) {answer=mid;left=mid+1;}else {right=mid-1;}
}
System.out.println(answer);}public static int[][] aa=new int[20000][2];public static int bb;public static int ccnumber;public static int check(int a) {int b;int c=0;for(b=0;b<bb;b++) {c=c+(aa[b][0]/a)*aa[b][1];if(c>=ccnumber) {return 1;}}if(c>=ccnumber) {return 1;}return 0;}
}
思维题目:
C - Minimize Abs 2 (atcoder.jp)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.security.PublicKey;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;import javax.naming.directory.SearchControls;public class Main {public static void main(String[] args) throws IOException {Scanner sc=new Scanner(System.in);BufferedReader br1=new BufferedReader(new InputStreamReader(System.in));PrintWriter pw1=new PrintWriter(System.out);
String[] aStrings=br1.readLine().split(" ");
long a=Long.parseLong(aStrings[0]);
long b=(long)(Math.sqrt(a)+1);
long c=0;
long answer=Long.MAX_VALUE;
while(c<=b) {long d=b*b+c*c;answer=Math.min(answer, (long)Math.abs(c*c+b*b-a));if(d>a) {b--;}else {c++;}
}
System.out.println(answer);}
}