zoukankan      html  css  js  c++  java
  • CF980D Perfect Groups

    首先发现如果一个数中含有平方因子,那么去掉平方因子不会对答案产生影响。

    所以对于一个串,去掉平方因子后,有多少种不同的数,权值就是多少。

    #include <bits/stdc++.h>
    #define reg register
    #define ll long long
    #define vi vector<int>
    #define SZ(x) (int) x.size()
    #define pb push_back
    using namespace std;
    const int MAXN = 5010;
    int n, tot, a[MAXN], b[MAXN], ans[MAXN];
    bool vis[MAXN];
    map<int, int> mp;
    int calc(int x) {
      if(x >= -1 && x <= 1) return x;
      int flag = 1;
      if(x < 0) flag = -1, x *= -1;
      for(reg int i = 2; i <= 10000; ++i) {
        if(i * i > x) break;
        while(x % (i * i) == 0) x /= i * i;
      }
      return x * flag;
    }
    void work() {
      scanf("%d", &n);
      for(reg int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]), a[i] = calc(a[i]);
        if(!mp[a[i]]) mp[a[i]] = ++tot, b[i] = tot;
        else b[i] = mp[a[i]];
      }
      for(reg int i = 1; i <= n; ++i) {
        tot = 0, memset(vis, 0, sizeof(vis));
        for(reg int j = i; j <= n; ++j) {
          if(a[j] == 0) {
            if(!tot) ++ans[1];
            else ++ans[tot];
          } else {
            if(!vis[b[j]]) vis[b[j]] = 1, ++tot;
            ++ans[tot];
          }
        }
      }
      for(reg int i = 1; i <= n; ++i) printf("%d ", ans[i]);
      puts("");
    }
    int main() {
      int _ = 1;
      // scanf("%d", &_);
      while(_--) work();
      return 0;
    }
    
  • 相关阅读:
    python协程爬取某网站的老赖数据
    python异步回调顺序?是否加锁?
    go语言循环变量
    使用memory_profiler异常
    安装python性能检测工具line_profiler
    等我!
    pytorch代码跟着写
    Python异常类型总结
    Python项目代码阅读【不断更新】
    夏令营体会
  • 原文地址:https://www.cnblogs.com/Lonely-233/p/13659025.html
Copyright © 2011-2022 走看看