程序go 2018-10-23 23:36 采纳率: 100%
浏览 363

在 c 中计算循环线性进程数据中的群集

What is the best possible algorithm for this problem below? I am curious to see the solutions/ideas stackoverflow community can come up with!

Let's assume that a timing register "X" counts up from any random number between 0 and 5000 and then increments unevenly at a random rate. If the timer overshoots 5000, it resets back to 0 and starts the counting process all over again. Each loop can be defined as a cluster and the "legal" clustering boundary is set between 0 to 1000. "Illegal" clusters have data points between 1001 and 5000.

Function count_time() can read back the value of the register "X" at any given time.

You will need to write an algorithmic function that counts the total legal clusters and will collect all the data points within every cluster. The algorithm will reject data points that is between 1001 and 5000, and will track the "illegal" clusters as well. This algorithmic function can be called as frequently as you want

The code below could be a sample solution skeleton, however, it might not be the best solution out there:

int repeat_every_1ms(void) //this function is called every 1ms
{
    static int unsigned count =  0;
    static int unsigned cluster = 1;
    static int unsigned legal_cluster = 1;
    static int unsigned illegal_cluster =  1;

    if (count >= count_time()) {
         //inside a cluster.it could be either legal or illegal.
         cluster++;
         count = count_time();  // Line 1 
         if(count <= 1000) {
             legal_cluster++;
             /* Start collecting data points (code not given) */
             // more statements...
         }
         count = count_time(); // polling count_time() value beacuse it can be different than Line 1
         if(count > 1000) {
              illegal_cluster++;
         }
    }
    count = count_time(); //get the final timestamp
    return 0;
}

转载于:https://stackoverflow.com/questions/52959152/counting-clusters-in-a-looping-linear-progression-data-in-c

  • 写回答

1条回答 默认 最新

  • devmiao 2018-10-26 07:05
    关注
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度