zoukankan      html  css  js  c++  java
  • Topcoder SRM 619 DIv2 500 --又是耻辱的一题

    这题明明是一个简单的类似约瑟夫环的问题,但是由于细节问题迟迟不能得到正确结果,结果比赛完几分钟才改对。。耻辱。

    代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #define ll long long
    using namespace std;
    #define NN 370000
    
    class ChooseTheBestOne
    {
    private:
    public:
        ll calc3(int n)
        {
            return (ll)pow(n,3);
        }
        int countNumber(int N)
        {
            ll now = 1,remain = (ll)(N-1);
            ll rd = 2;
            ll pos;
            int has[5005];
            memset(has,-1,sizeof(has));
            has[0] = 0;
            while(rd < N)
            {
                while(has[now] == 0)
                {
                    now = (now+1)%N;
                }
                ll call = calc3(rd);
                ll add = (call-1)%remain;
                ll k = 0;
                for(pos=now;k<add;)
                {
                    pos = (pos+1)%N;
                    if(has[pos] != 0)
                        k++;
                }
                has[pos] = 0;
                now = (pos+1)%N;
                //cout<<"出去: "<<pos+1<<"   现在"<<now+1<<endl;
                remain--;
                rd++;
    
            }
            ll i;
            for(i=0;i<N;i++)
            {
                if(has[i] == -1)
                {
                    return i+1;
                }
            }
        }
    };
    
    int main()
    {
        ChooseTheBestOne *kc = new ChooseTheBestOne();
        cout<<(*kc).countNumber(1234)<<endl;
        return 0;
    }
    View Code
  • 相关阅读:
    RSA 与 DSA
    atlassian
    Cygwin
    windows下编写的Shell脚本在Linux下运行错误的解决方法
    NSKeyValueObserving(KVO)
    UIBezierPath 的使用介绍
    Objective
    Objective-C 内存管理原则
    Mac OSX 快捷键&命令行总览
    浅析Objective-C字面量
  • 原文地址:https://www.cnblogs.com/whatbeg/p/3710366.html
Copyright © 2011-2022 走看看