zoukankan      html  css  js  c++  java
  • 编程之美第一题,参考某同事的算法和文章

                Process p = Process.GetCurrentProcess();

                
    const double SPLIT = 0.01;
                
    const int COUNT = 200;
                
    const double PI = 3.14159265;
                
    const int INTERVAL = 100;

                
    double[] busySpan = new double[COUNT];  //array of busy times
                double[] idleSpan = new double[COUNT];  //array of idle times
                int half = INTERVAL / 2;

                
    double radian = 0.0;
                
    for (int i = 0; i < COUNT; i++)
                {
                    busySpan[i] 
    = (double)(half + (Math.Sin(PI * radian) * half));
                    idleSpan[i] 
    = INTERVAL - busySpan[i];
                    radian 
    += SPLIT;
                }

                
    double startTime = 0;
                
    int j = 0;

                
    while (true)
                {
                    j 
    = j % COUNT;

                    startTime 
    = Environment.TickCount;

                    p.ProcessorAffinity 
    = (IntPtr)0x0001;
                    
    while ((Environment.TickCount - startTime) <= busySpan[j]) ;

                    p.ProcessorAffinity 
    = (IntPtr)0x0002;
                    
    while ((Environment.TickCount - startTime) <= idleSpan[j]) ;

                    j
    ++;
                }
  • 相关阅读:
    oc中 中文到拼音的转换
    ios 添加全屏返回手势
    自我总结- CGAffineTransform
    解决pod search出来的库不是最新
    四舍五入的函数,保留小数点后几位数不四舍五入
    iOS 键盘变中文
    LanguageImage尺寸
    打包上传64位支持的解决办法
    第1年11月2日 ssh分发秘钥时出现错误“Permission denied (publickey,gssapi-keyex,gssapi-with-mic)” yarn
    第1年11月1日 uniapp原生
  • 原文地址:https://www.cnblogs.com/Jax/p/1695295.html
Copyright © 2011-2022 走看看