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的更多相关文章
随机推荐
- HDU 1387 Team Queue( 单向链表 )
Team Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- CTU Open 2018 Lighting /// 组合数递推 二进制
题目大意: 给定n k 给定一个数的二进制位a[] 求这个数加上 另一个二进制位<=n的数b 后 能得到多少个不同的 二进制位有k个1 的数 样例 input10 51000100111 out ...
- docker--container的port映射
使用nginx为例 先运行nginx [root@localhost ~]# docker run --name web -d nginx Unable to find image 'nginx:la ...
- js 模拟window.open 打开新窗口
为什么要去模拟window.open() 打开一个 新的窗口呢,因为有些浏览器默认会拦截 window.open, 当需要函数中打开新窗口时,接可以使用a标签去模拟打开. /** * a模拟windo ...
- iview 分割面板效果(一)基本原理
方法一: 基本点就是:利用“子绝父相(子元素相对于父元素进行定位)”, 左侧的pane设置为left:0;right:a%, 则右侧的设置为right:0;left:(100-a)%. 如果左右之间有 ...
- Linux系统分辨率设置
linux 设置分辨率 如果你需要在linux上设置显示屏的分辨率,分两种情况:分辨率模式存在与分辨率模式不存在,具体如下. 1,分辨率模式已存在 1)如何查询是否存在: 图形界面:在System S ...
- StarUML 破解方法2.X(转)
下载地址:https://www.jb51.net/softs/558248.html#download 在安装目录的:StarUML\www\license\node 找到LicenseManage ...
- 【串线篇】SQL映射文件delete/ insert/ update标签
一. <insert id="insertEmployee"> INSERT INTO t_employee(empname,gender,email) VALUES( ...
- java--CharAt,StartWith
public class CharAtStartWithDemo { public static void main(String[] args){ //jdk8 testCharAt();//1 t ...
- shell脚本编程测试类型下
一bash的数值测试 -v VAR变量VAR是否设置 数值测试:-gt 是否大于greater-ge 是否大于等于-eq 是否等于-ne 是否不等于 not equal-lt 是否小于-le 是否小 ...