2018 腾讯笔试 算法题

今天运气比较好,做的几个算法题还算简单,第一遍本来想先用暴力解法解出来再慢慢调通过率,结果居然一遍就过了,
其实思路很简单,没有任何技巧可言,估计是给的测试用例太少所以侥幸一遍过了,最近笔试多,挖个坑后面再调优吧


import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        for(int j=1; j <= num; j++){
            int A = sc.nextInt();
            int B = sc.nextInt();
            int C = sc.nextInt();
            for (int i = 1; i <= 10000; i++) {
                if(i*A%B == C){
                    System.out.println("YES");
                    break;
                }
                if(i == 10000 && i*A%B != C){
                    System.out.println("NO");
                }
            }
        }
    }
}

#腾讯##笔试题目#
全部评论
有木有大神帮忙看一下这一题下面的代码哪里出错了,笔试时一直不通过。。。 #include <iostream> using namespace std; int main() {     int n;     while (cin >> n)     {         int num = 3 * n;         int *arr = new int[num];         for (int i = 0; i < num; i++)             cin >> arr[i];         for (int i = 0; i < num; i = i + 3)         {             int a = arr[i];             int b = arr[i+1];             int c = arr[i+2];             if ((c == 0)|| ((a% b)==c))                 cout << "YES" << endl;             else             {                 for (int j = 2;; j++)                 {                     if ((j*a)%b == c)                     {                         cout << "YES" << endl;                         break;                     }                     else if(((j*a)%b)== (a% b))                     {                         cout << "NO" << endl;                         break;                     }                 }             }         }         delete[] arr;     }     return 0; }
点赞 回复 分享
发布于 2018-09-17 10:31
暴力能过==数据太水==垃圾题emmm
点赞 回复 分享
发布于 2018-09-19 19:56

相关推荐

点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务