腾讯java笔试
import java.util.*; public class Main{ static boolean[][] isReach; public static void main(String[] args){ Scanner in = new Scanner(System.in); int n = in.nextInt(); int m = in.nextInt(); isReach = new boolean[n][n]; for(int i = 0;i < m;i++){ isReach[in.nextInt()-1][in.nextInt()-1] = true; } for(int i = 0;i < n;i++){ for(int j = 0;j < n;j++){ if(i!=j&&isReach[i][j]){ dfs(i,j,n); } } } int[][] num = new int[n][2]; for(int i = 0;i<n;i++){ for(int j = 0;j < n;j++){ if(isReach[i][j]){ num[i][0]++; num[j][1]++; } } } int sum = 0; for(int i = 0;i < n;i++){ if(num[i][1]>num[i][0]){ //System.out.println(Arrays.deepToString(isReach)); sum++; } } System.out.println(sum); } public static void dfs(int begin,int end,int n){ for(int i = 0;i < n;i++){ if(i==end)continue; if(isReach[end][i]&&!isReach[begin][i]&&begin!=i){ isReach[begin][i]=true; dfs(begin,i,n); } } } }
腾讯第二个,重要城市判定
import java.util.*; public class Main{ public static void main(String[] args){ Scanner in = new Scanner(System.in); int t = in.nextInt(); for(int i = 0;i < t;i++){ int a = in.nextInt(); int b = in.nextInt(); int c = in.nextInt(); boolean flag = false; for(int j = 1;j <= 100*a;j++){ if(j*a%b==c){ flag = true; break; } } if(flag) System.out.println("YES"); else System.out.println("NO"); } } }
腾讯第三个,判断取余追美女的,,
我感觉最后一个ac的很蠢。。。。。。。。。。。直接暴力
第一个也想m++暴力来着没赶趟。。。。。。
#腾讯#