Editorial for Tam giác vuông
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Lưu ý: Các code mẫu dưới đây chỉ mang tính tham khảo và có thể không AC được bài tập này
Code mẫu của ladpro98
#include <iostream> #include <cstdio> #include <algorithm> const int N = 100005; using namespace std; int x[N], y[N], cx[N], cy[N]; int n; int main() { ios :: sync_with_stdio(0); cin.tie(0); cin >> n; for(int i = 1; i <= n; i++) { cin >> x[i] >> y[i]; cx[x[i]]++, cy[y[i]]++; } long long res = 0; for(int i = 1; i <= n; i++) res += (long long)(cx[x[i]] - 1) * (cy[y[i]] - 1); cout << res; }
Code mẫu của skyvn97
import java.util.*; import java.lang.*; import java.io.*; public class Main { public static void main(String args[]) { InputStream inputStream=System.in; OutputStream outputStream=System.out; InputReader in=new InputReader(inputStream); PrintWriter out=new PrintWriter(outputStream); VOSRTRI solver=new VOSRTRI(); solver.solve(in,out); out.close(); } }; class VOSRTRI { public void solve(InputReader in,PrintWriter out) { int n=in.nextInt(); Point[] a=new Point[n]; for (int i=0;i<n;i=i+1) a[i]=new Point(in); int countX[]=new int[MAX]; int countY[]=new int[MAX]; Arrays.fill(countX,0); Arrays.fill(countY,0); for (int i=0;i<n;i=i+1) countX[a[i].x]++; for (int i=0;i<n;i=i+1) countY[a[i].y]++; long res=0; for (int i=0;i<n;i=i+1) res+=((long)countX[a[i].x]-1)*(countY[a[i].y]-1); out.println(res); } class Point { int x,y; public Point(InputReader in) { x=in.nextInt(); y=in.nextInt(); } }; static final int MAX=100100; }; class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader=new BufferedReader(new InputStreamReader(stream),32768); tokenizer=null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } };
Comments