zoukankan      html  css  js  c++  java
  • codeforces 577

    codeforces 577A

    题目链接http://codeforces.com/problemset/problem/577/A

    题目大意:给出一个n*n的表格,每个表格对应的值为横坐标*纵坐标,然后给一个数x,求数x在表格中出现了几次(具体请看题意)

    题目分析1 ≤ n ≤ 10^5, 1 ≤ x ≤ 10^9

    方案一:用n*n的循环,记录每个表格中对应的数据,但时间复杂度是10^10,必定会超时,所以,排除这种方法

    方案二:题目可以转化为求x的的约数有几个,x的约数最大为10

    代码实现

    #include<bits/stdc++.h>
    
    using namespace std;
    
    int main()
    {
        int ans=0;
        int n,x,t,a;
        scanf("%d %d",&n,&x);
        for(int i=x;i>=1;i--)
        {
            if(i>n)
                continue;
            //printf("i==%d
    ",i);
            t=x%i;
            a=x/i;
            if(t==0&&a<=n)
            {
               // printf("a==%d
    ",a);
                ans++;
            }
        }
        printf("%d
    ",ans);
        return 0;
    }

    codeforces 577B

    题目链接http://codeforces.com/contest/577/problem/B

    题目大意:给出n个数,从中挑选出一些数让它们的和是k的倍数,若能找到满足条件的输出yes,否则输出no

    题目分析:如果n>k,则一定能满足条件;当n<=k,n个数组成的数可能相同,每次判断很耗时间,所以,用set容器将和全都存储起来,set容器会自动去重。

    代码实现

    anytime you feel the pain.hey,refrain.don't carry the world upon your shoulders
  • 相关阅读:
    菜根谭#77
    菜根谭#76
    菜根谭#75
    菜根谭#74
    菜根谭#73
    python迭代器
    python爬取网页数据
    yii2验证规则
    python装饰器的理解
    php中多图上传采用数组差集处理(array_diff,array_map)
  • 原文地址:https://www.cnblogs.com/gaoss/p/4814407.html
Copyright © 2011-2022 走看看