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;
    }
    
  • 相关阅读:
    个人附加作业
    个人作业3——个人总结(Alpha阶段)
    四则运算-单元测试
    英语学习APP案例分析
    基于GUI的四则运算
    基于控制台的四则运算
    对forEach、for-in还有es6的for-of的一些整理
    ASP.NET学习笔记5
    ASP.NET学习笔记4
    String类型的二进制数求和
  • 原文地址:https://www.cnblogs.com/Lonely-233/p/13659025.html
Copyright © 2011-2022 走看看