zoukankan      html  css  js  c++  java
  • AtCoder Grand Contest 003 D

    题目传送门:https://agc003.contest.atcoder.jp/tasks/agc003_d

    题目大意:

    给定(n)个数(s_i),要求从中选出尽可能多的数,满足任意两个数之积都不是完全立方数


    对于每个数(s_i),有(s_i=prodlimits_{i=1}^mp_i^{k_i}),则我们令(a_i=prodlimits_{i=1}^mp_i^{k_i\%3}),然后我们用(a_i)代替(s_i)来进行考虑,

    对于每个(a_i),满足(a_i×a_j)为立方数的(a_j)只有一种取值,我们可以贪心地选择出现次数较多的那一种

    预处理出(sqrt[3]{S})内的质数,对于每个(s_i)可以在(O(M+log s_i))的时间内求出(a_i)

    然后对于考虑每个质因子的次数,可以求出(a_j)

    (其实这题时限够大,可以预处理质数)

    /*program from Wolfycz*/
    #include<map>
    #include<cmath>
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #define Fi first
    #define Se second
    #define inf 0x7f7f7f7f
    #define sqr(x) ((x)*(x))
    #define cub(x) ((x)*(x)*(x))
    using namespace std;
    typedef long long ll;
    typedef unsigned int ui;
    typedef unsigned long long ull;
    inline char gc(){
    	static char buf[1000000],*p1=buf,*p2=buf;
    	return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
    }
    inline int frd(){
    	int x=0,f=1; char ch=gc();
    	for (;ch<'0'||ch>'9';ch=gc())	if (ch=='-')	f=-1;
    	for (;ch>='0'&&ch<='9';ch=gc())	x=(x<<3)+(x<<1)+ch-'0';
    	return x*f;
    }
    inline int read(){
    	int x=0,f=1; char ch=getchar();
    	for (;ch<'0'||ch>'9';ch=getchar())	if (ch=='-')	f=-1;
    	for (;ch>='0'&&ch<='9';ch=getchar())	x=(x<<3)+(x<<1)+ch-'0';
    	return x*f;
    }
    inline void print(int x){
    	if (x<0)	putchar('-'),x=-x;
    	if (x>9)	print(x/10);
    	putchar(x%10+'0');
    }
    const int N=1e5;
    ll A[N+10],B[N+10];
    map<ll,int>Mp;
    int main(){
    	int n=read();
    	for (int i=1;i<=n;i++){
    		ll x,y=1;
    		scanf("%lld",&x);
    		for (ll j=2;cub(j)<=x;j++)	while (x%cub(j)==0)	x/=cub(j);
    		map<ll,int>::iterator it=Mp.find(x);
    		if (it==Mp.end())	Mp.insert(map<ll,int>::value_type(x,1));
    		else	it->Se++;
    		A[i]=x;
    		for (ll j=2;cub(j)<=x;j++){
    			if (x%j==0){
    				y*=(x%sqr(j)==0)?j:sqr(j);
    				while (x%j==0)	x/=j;
    			}
    		}
    		y*=(sqr((ll)sqrt(x))==x)?(ll)sqrt(x):sqr(x);
    		B[i]=y;
    	}
    	int Ans=0;
    	map<ll,int>::iterator it=Mp.find(1);
    	if (it!=Mp.end())	Ans++,it->Se=0;
    	for (int i=1;i<=n;i++){
    		int res=0;
    		map<ll,int>::iterator x=Mp.find(A[i]);
    		map<ll,int>::iterator y=Mp.find(B[i]);
    		if (x!=Mp.end())	res=max(res,x->Se),x->Se=0;
    		if (y!=Mp.end())	res=max(res,y->Se),y->Se=0;
    		Ans+=res;
    	}
    	printf("%d
    ",Ans);
    	return 0;
    }
    
  • 相关阅读:
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    并行导致的进程数过大无法连接数据库
    Oracle 等待事件(Wait Event):Sync ASM rebalance 解析
    2套RAC环境修改scanip后客户端连接异常
    数据流通技术工具
    Hack The Box——Scavenger
    MySQL中InnoDB引擎对索引的扩展
    30分钟,教你从0到1搞定一次完整的数据可视化分析!
    【2020-MOOC-浙江大学-陈越、何钦铭-数据结构】树和堆(第五周的笔记和编程作业)
  • 原文地址:https://www.cnblogs.com/Wolfycz/p/10167770.html
Copyright © 2011-2022 走看看