zoukankan      html  css  js  c++  java
  • CodeForces485A——Factory(抽屉原理)

    Factory


    One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were x details in the factory storage, then by the end of the day the factory has to produce (remainder after dividing x by m) more details. Unfortunately, no customer has ever bought any mythical detail, so all the details produced stay on the factory.
    The board of directors are worried that the production by the given plan may eventually stop (that means that there will be а moment when the current number of details on the factory is divisible by m).
    Given the number of details a on the first day and number m check if the production stops at some moment.
    Input
    The first line contains two integers a and m (1 ≤ a, m ≤ 105).
    Output
    Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No".
    Sample test(s)
    Input
    1 5
    Output
    No
    Input
    3 6
    Output
    Yes

    题目大意:

        一个工厂,仓库中有X个产品,那么当天就生产X mod M个产品。给一个A代表仓库中的产品个数,问是否存在工厂停工的一天。即X mod M = 0。

    解题思路:

        错误思路:

          当时拿到第一组样例进行验算发现:

          第一天 1 5 生产1件

          第二天 2 5 生产2件

          第三天 4 5 生产4件

          第四天 8 5 生产3件

          第五天 11 5 生产1件

          第六天 12 5 生产2件

          可以看到每天的生产数每4天一循环。

          X mod M的结果属于[0,M-1]。那么最多要是在M天以内没有出现 X mod M==0 的情况,就不会在出现了。(根据抽屉原理第M+1次必会重复,但是若出现0就结束判断,只需判断循环M次会不会出现0即可)

    Code:

     1 /*************************************************************************
     2     > File Name: CF485A.cpp
     3     > Author: Enumz
     4     > Mail: 369372123@qq.com
     5     > Created Time: 2014年11月06日 星期四 00时47分17秒
     6  ************************************************************************/
     7 
     8 #include<iostream>
     9 #include<cstdio>
    10 #include<cstdlib>
    11 #include<string>
    12 #include<cstring>
    13 #include<list>
    14 #include<queue>
    15 #include<stack>
    16 #include<map>
    17 #include<set>
    18 #include<algorithm>
    19 #include<cmath>
    20 #include<bitset>
    21 #include<climits>
    22 #define MAXN 100000
    23 using namespace std;
    24 int main()
    25 {
    26     int a,b;
    27     cin>>a>>b;
    28     int t=b;
    29     while (t--)
    30     {
    31         if ((a+a%b)%b==0)
    32         {
    33             printf("Yes");
    34             return 0;
    35         }
    36         else
    37             a=(a+a%b)%b;
    38     }
    39     printf("No");
    40     return 0;
    41 }
  • 相关阅读:
    长沙Uber司机奖励政策(8月24日到8月30日)
    苏州Uber优步司机奖励政策(8月31日至9月6日)
    武汉Uber优步司机奖励政策(8月31日~9月6日)
    青岛Uber司机奖励政策(8月31号~9月6号)
    成都Uber优步司机奖励政策(8月31日~9月6日)
    成都UBER优步司机第六组奖励政策
    敏捷软件开发--敏捷开发原则
    UML--对象的介绍
    ip 子网掩码 网关 DNS
    敏捷软件开发--计划
  • 原文地址:https://www.cnblogs.com/Enumz/p/4078439.html
Copyright © 2011-2022 走看看