CF963
CF963C
首先假设横向被分成p块纵向被分成q块,\(C_i\)为横向长度为\(i\)的方块个数,\(D_i\)为纵向长度为\(i\)的方块个数
\(p\times q=\)总块数T,q要是所有\(C_i\)的gcd的因数,p是所有\(D_i\)的gcd的因数
然后随手一交发现不对,比如\(1\times 1=2, 1\times 2=1, 2\times 1=1, 2\times 2=2\)
设长x宽y的块有\(w_{x,y}\)个,这就要求对于制定的长x\(w_{x,1}:w_{x,2}:\cdot \cdot \cdot :w{x,k}=D_1:D_2:\cdot \cdot \cdot :D{k}\)
冷静分析一下就是\(\frac{w_{x,y}}{C_x}=\frac{D_y}{T}\)
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<map>
#include<cmath>
#define LL long long
#define LD long double
using namespace std;
const int M = 1000001;
map<LL,LL>mg,mh;
LL T,n,m,k,x,y,c,G,H,res,a[M],b[M],d[M];
LL gcd(LL x,LL y)
{
if(!y) return x;
return gcd(y,x%y);
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>x>>y>>c;
if(mg.find(x)==mg.end()) mg[x]=0;
if(mh.find(y)==mh.end()) mh[y]=0;
mg[x]+=c; mh[y]+=c;
T+=c;
a[i]=x, b[i]=y, d[i]=c;
}
map<LL,LL>::iterator it;
it=mg.begin();
while(it!=mg.end()) G=gcd(G,it->second),it++;
it=mh.begin();
while(it!=mh.end()) H=gcd(H,it->second),it++;
for(int i=1;i<=n;i++)
{
if(fabs((LD)d[i]/mg[a[i]]-(LD)mh[b[i]]/T)>1e-10)
{
printf("0");
return 0;
}
}
if(H<G) swap(H,G);
LL k=sqrt(G);
for(int i=1;i<=k;i++) if(G%i==0)
{
if(T%i==0 && H%(T/i)==0) res+=1ll;
if(i*i!=G && T%(G/i)==0 && H%(T/(G/i))==0) res+=1ll;
}
cout<<res;
}
CF963的更多相关文章
随机推荐
- Apache Shiro 认证+授权(一)
1.核心依赖 <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-co ...
- SQLAlchemy应用到Flask中
安装模块 pip install Flask-SQLAlchemy 加入Flask-SQLAlchemy第三方组件 from flask import Flask # 导入Flask-SQLAlche ...
- hdu3438 Buy and Resell(优先队列+贪心)
Buy and Resell Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- RabbitMq--3--案例
https://blog.csdn.net/hellozpc/article/details/81436980
- android pull 解析器解析xml文档
person.xml <?xml version="1.0" encoding="UTF-8"?> <persons> <pers ...
- 轻量级Spring定时任务(Spring-task)
Spring3.0以后自主开发的定时任务工具,spring-task,可以将它比作一个轻量级的Quartz,而且使用起来很简单,除spring相关的包外不需要额外的包,而且支持注解和配置文件两种形式. ...
- 最大公因数数gcd模板
首先蒟蒻是在大佬的博客里学习的代码,代码风格多有相似之处,大佬博客https://www.cnblogs.com/lMonster81/p/10433902.html 最大公因数那,顾名思义就是两个数 ...
- linux CentOS7 nginx nginx-rtmp-module搭建直播
直播配置 1. 安装 Nginx 依赖软件 yum -y install gcc gcc-c++ autoconf automake make yum -y install zlib zlib-dev ...
- oracle 数据恢复
闪回表删除之前 flashback table t1 to before drop; 如果彻底删除表此方法无效 若要彻底删除表,则使用语句:drop table <table_name> ...
- sqoop 数据导入hive
一. sqoop: mysql->hive sqoop import -m 1 --hive-import --connect "jdbc:mysql://127.0.0.1:3306 ...