zoukankan      html  css  js  c++  java
  • The 14th UESTC Programming Contest Final B

    B - Banana Watch

    Time Limit: 1000/1000MS (Java/Others)     Memory Limit: 262144/262144KB (Java/Others)
     

    As a famous technology company, Banana Inc. invents Banana Watch, redefining the watch.

    While a normal watch has 12 indexes and two or three moving hands, a Banana Watch has n indexes and a moving hand.

    The moving hand is at 0 initially, and in 1st second, it turns 1 index clockwise; in 2nd second, it turns 2 indexes clockwise; ... ;

     in ith second, it turns 
    i
     indexes clockwise. When it moves back to 0 exactly, one minute passes (Yes, Banana Inc. also redefines the minute).

    How many seconds in the first minute?


    Input

    One integer n.

    3n106

    Sample input and outputOutput

    Print the number of seconds in the first minute.

    Sample Input Sample Output
    3
    2
    5
    4

    Hint

    If n=5, in 1st second, the hand moves to 1; in 2nd second, the hand moves to 3; in 3rd second, the hand moves to 1; in 4th second, 

    the hand moves to 0. So the answer for n=5 is 4.


    My Solution

    用sum[i]表示1~i的和,然后,从1 ~ maxn 查找。第一次出现if((sum[i] %= n) == 0) {printf("%d", i); break;}

    然后考虑到数据范围。所以第一发有maxn = 2000000 + 1000,然后就过了。

    假设用 1000000 + 8可能过也可能过不了。

    #include <iostream>
    #include <cstdio>
    using namespace std;
    const int maxn = 2000000 + 1000;
    long long sum[maxn];
    int main()
    {
        int n;
        scanf("%d", &n);
        sum[0] = 0;
        for(int i = 1; i < maxn; i++){
            sum[i] += sum[i-1]+i;
            if((sum[i] %= n) == 0) {printf("%d", i); break;}
        }
        return 0;
    }

    Thank you!


  • 相关阅读:
    ASP.NET上传文件的三种基本方法
    实例分析 equals 和 ==
    如何保证Web Service的安全
    Winform动态显示图片,数据流方式
    C# 文件保存到数据库中或者从数据库中读取文件
    简说Session
    NotifyIcon的简单使用
    c# Invoke和BeginInvoke 区别
    DataGridView 的 CurrentCellDirtyStateChanged事件用法
    十种发送邮件的方式
  • 原文地址:https://www.cnblogs.com/wzjhoutai/p/7295471.html
Copyright © 2011-2022 走看看