首页 > 其他分享 >【AGC047A】Integer Product

【AGC047A】Integer Product

时间:2023-02-05 17:44:12浏览次数:137  
标签:Product 题解 mid long res 标程 Integer AGC047A

思路和标程类似,但是没用 map

首先 \(n^2\) 暴力显然不过我不敢保证你会不会被卡掉精度

看到数据范围果断想低于 \(n^2\) 的做法。

小数点后不超过 \(9\) 位,这能给我们什么启示?

将每个 \(A_i\) 乘上 \(10^9\),记为 \(B_i\)。容易发现若 \(A_i\times A_j\) 为整数,\(10^{18}\mid B_i\times B_j\)。

而小学数学告诉我们,若一个数有 \(m\) 个因子 \(2\),\(n\) 个因子 \(5\),它末尾零的个数为 \(\min(m,n)\)。

标程使用 map,但是实际上这个数字并不大,直接用桶记录。

#include <map>
#include <stdio.h>
long long f[50][50];
int n,i,j,p,q,cnt1,cnt2;
long long mid,res;
long double x;
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;++i)
	{
		cnt1=cnt2=0;
		scanf("%Lf",&x);
		mid=(long long)(x*1000000000+0.5);
		while(mid%2==0)
		{
			++cnt1;
			mid/=2;
		}
		while(mid%5==0)
		{
			++cnt2;
			mid/=5;
		}
		++f[cnt1][cnt2];
	}
	for(i=18;i<=90;++i)
	{
		for(j=18;j<=90;++j)
		{
			for(p=0;p<45&&p<=i;++p)
			{
				for(q=0;q<45&&q<=j;++q)
				{
					if(i-p>44||j-q>44)
						continue;
					if(i!=2*p||j!=2*q)
						res+=f[p][q]*f[i-p][j-q];
					else
						res+=f[p][q]*(f[p][q]-1);
				}
			}
		}
	}
	printf("%lld",res>>1);
	return 0;
}

写挂时参考了网上题解官方题解

表示膜拜。

标签:Product,题解,mid,long,res,标程,Integer,AGC047A
From: https://www.cnblogs.com/Syara/p/17093694.html

相关文章

  • HDU 6441 Find Integer (费马大定理)
    Description:peopleinUSSSlovemathverymuch,andthereisafamousmathproblemgiveyoutwointegersn,a,youarerequiredtofind......
  • Educational Codeforces Round 75 C Minimize The Integer
    这道题的意思就是给出一个由数字组成的字符串,相邻的数字可以互换位置,但是如果相邻的为同奇同偶这样就不能交换。让我们求交换任意次数可以产生的最小数。这条限制就是说......
  • POJ3468 A Simple Problem with Integers(SplayTree做法)
    DescriptionYouhave N integers, A1, A2,..., AN.Youneedtodealwithtwokindsofoperations.Onetypeofoperationistoaddsomegivennumbertoea......
  • Integer 127 128
    publicclassTestInteger{publicstaticvoidmain(String[]args){//1.127--127范围内正确 Integerone=127;Integertwo=127......
  • java面试技巧:Integer和int的那些事⼉
    最近在招聘⾯试的过程中,考察⼀些候选⼈的基础掌握能⼒中发现,还是有⼤多数⼲了有1~3年的开发者在基础这块⼉掌握的不够牢靠,没有去思考过为什么这样做,以及这样做的原因是什么?......
  • API(BigInteger,BigDecimal)
    BigInteger的对象一旦创建,内部的值不会发生改变,如果参与运算,则会产生一个新的BigIneger对象来接收如果BigInteger的值没有超过long的范围,可以用静态方法获取//静态方法......
  • int和Integer使用==比较
    packagecom.cpt.first;/***@PackageName:com.cpt.first*@ClassName:Test02*@Author:cpt*@Date:2023/1/211:36*@Description:**/publicclassTest......
  • 23/1/119-LeetCode 08:String to Integer (atoi)
    思路主要是对于前面的零,可以不用再去特殊判断了嘛。直接当成普通的数字直接算就好,反正算完之后ans=0,nodifference;对于超出范围,这个一直都是我不太注意的地方,这里max=2^......
  • Otto Group Product Classification
    遇到的坑:做多分类,用CrossEntropyLoss时,训练时候的正确标签的范围应该是[0,n-1],而不是[1,n],不然会报IndexError:Targetisoutofbounds比如这题就应该预处理为[0,8],......
  • [LeetCode]7. Reverse Integer (easy)
    ​​WelcomeToMyBlog​​7.ReverseInteger(easy)1.在java中,数值溢出后还能计算,只不过得到的计算结果不正确,可以设置两个变量并利用这一点进行溢出判断2.因为......