|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import java.util.*;
public class Main{
public static int gcd(int a,int b) {
return b==0? a:gcd(b, a%b);
}
public static void main(String[] args) {
Set<String> set = new HashSet<>();
Set<Integer> set2 = new HashSet<>();
int x = 19,y = 20;
for (int i = 0; i <=x; i++) {
for (int j = 0; j <=y; j++) {
set2.add(i*100+j);
}
}
List<Integer> list = new ArrayList<>(set2);
for (int i = 0; i <list.size(); i++) {
int a = list.get(i);
for (int j = i+1; j <list.size(); j++) {
int b = list.get(j);
int x1 = a/100;
int y1 = a%100;
int x2 = b/100;
int y2 = b%100;
int up = x2-x1;
int down = y2-y1;
int temp1 = gcd(up, down);
String k = (up/temp1)+" "+(down/temp1);
if (down==0) {
set.add("x="+x2);
continue;
}
int c = y1*down-x1*up;
int temp2 = gcd(c, down);
String bb = (c/temp2)+" "+(down/temp2);
set.add(k+" "+bb);
}
}
System.out.println(set.size());
}
}
以上代码和图片中出了变量名究竟还有哪里不一样?为什么我结果就是不对。。。心态崩了
没学过java, 但是你的 up 和 down 和图中是相反的
|
-
|