C. Candy Store(数学)
Problem - C - Codeforces
给定我们n种糖果,已知每种糖果的总的数量ai和 单价bi,让我们每种糖果打包,每种糖果每包的价格为ci ,每包的数量为di ,ci = bi * di,ai是di的倍数,问我们通过合理的安排,最少有几种ci
ai能够整除di,ai * bi 能够整除 bi * di ,也就是说 ai * bi 能够整除ci
在一段ci相同的区间中,ci是bi的公倍数,ai * bi 是ci 的公倍数
gcd : 最大公约数,lcm:最小公倍数
也就是 gcd(ai*bi , a(i+1) * b (i+1), ....) 能够整除 lcm(b[i],b[i+1] ,...) ,整除完就是这一段的ci
随着区间的增大,gcd递减,lcm递增,gcd/lcm 递减
LCM[0,a]=0,GCD[0,a]=|a|,LCM[a,a]=|a|,GCD[a,a]=|a|
#include <iostream>
#include <bits/stdc++.h>
#include <cstring>
#include <vector>
#include <unordered_map>
#include <queue>
#include <set>
#define int long long
#include <algorithm>
#define x first
#define y second
#define pb emplace_back
#define fu(i,a,b) for(int i=a;i<=b; ++ i)
#define fd(i,a,b) for(int i=a;i>=b; -- i)
#define endl '\n'
#define ms(x,y) memset(x,y,sizeof x)
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;typedef long long LL;
typedef unsigned long long ULL;
typedef vector<vector<LL>> VVL;
typedef vector<vector<int>> VVI;
typedef vector<LL> VL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef pair<PII,int> PIII;
typedef pair<double,double> PDD;
typedef pair<double,int> PDI;
typedef pair<char,int> PCI;
typedef pair<string,int> PSI;
typedef pair<int,string> PIS;
typedef pair<int,char> PIC;
typedef pair<LL,LL> PLL;
typedef __int128 i128;
typedef unsigned long long ULL;
const int N =1e6 + 10,M = N * 5,base =400 ,INF = 0x3f3f3f3f,P = 131;
const double eps = 1e-8;
const int mod = 998244353;
const LL LNF=(LL) INF * INF;int n;LL gcd(LL a,LL b) // 最大公约数
{return b?gcd(b,a%b):a;
}
LL lcm(LL a,LL b) // 最小公倍数
{return a * b / gcd(a,b);
}
// ai 第i个糖果的总个数
// bi 第i个糖果的单个费用
// ci 打包完 一包糖果的价格
// di 一包糖果的数量 inline void solve()
{cin >> n;VL a(n+1),b(n+1); fu(i,1,n) cin >> a[i] >> b[i];LL g=0,m = 1; int ans = 1; fu(i,1,n){if(gcd(g,a[i] * b[i]) % lcm(m,b[i]) != 0 ) // 需要新增一个ci区间{ans++;g=0,m = 1; }g = gcd(g,a[i] * b[i]);m = lcm(m,b[i]);}cout << ans <<endl;}
signed main()
{
// freopen("1.txt","r",stdin);#define int long long
// init(N-1);ios
// cout << fixed<<setprecision(2);int t=1;cin>>t;int now = 1;while(t -- ){
// cout<<"Case ";
// cout<<"Case #";
// cout<<"Scenario #";
// cout<< now ++ <<": ";
// cout<< now ++ <<": \n";solve();}return 0;
}
C. Candy Store(数学)相关推荐
- UVa 1639 - Candy(数学期望 + 精度处理)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- 美国英语与英国英语的区别(二)
美国英语与英国英语在词汇.语法.拼法.读音和其它等方面存在着许多差异. 1.词汇方面的差异 美国英语所特有的词汇和短语可分为三类:第一类是美国人创造的新词,如movie(电影).bootlegger( ...
- 基于HTML5实现的(本地存储)多标签页面元素的复制粘贴
历史 在HTML5本地存储之前,如果我们想在客户端保存持久化数据,有这么几个选择: HTTP cookie.HTTP cookie的缺点很明显,最多只能存储4KB的数据,每个HTTP请求都会被传送回服 ...
- Web - 客户端存储的几种方式
客户端存储主要方便一些APP离线使用.今天就来说说客户端存储的方法有多少? 说在最前面的一句:所有的客户端存储都有一个原则:读写的数据必须要同域 1 Cookie Cookie是一项很老的技术的,就是 ...
- HTML5本地存储不完全指南
历史 在HTML5本地存储之前,如果我们想在客户端保存持久化数据,有这么几个选择: HTTP cookie.HTTP cookie的缺点很明显,最多只能存储4KB的数据,每个HTTP请求都会被传送回服 ...
- 高安全性同态加密算法_坏的同态性教程
高安全性同态加密算法 I was going to write at length about the issues I see in neumorphism and why this trend s ...
- TensorFlow神经网络(九)VGG net论文阅读笔记
[注]内容来自MOOC人工智能实践TensorFlow笔记课程第8讲 来源:2015 ICLR 用于图像分类的文章: Very Deep Convolutional Networks for Larg ...
- ValueError: You are trying to load a weight file containing 0 layers into a model with 16 layers.
ValueError: You are trying to load a weight file containing 0 layers into a model with 16 layers. 在使 ...
- imagenet数据集类别标签和对应的英文中文对照表
预测结果输出one-hot类型,最大概率的下标即为对于类别号 0: 'tench, Tinca tinca', 丁鲷(鱼) 1: 'gold ...
最新文章
- 3d打印主要的切片参数类型_3D打印机教程 | 模型切片参数设置教程
- 结构体对齐,结构体深拷贝和浅拷贝
- 什么能在main()函数之前或之后执行
- Spring Boot集成Redis,这个坑把我害惨了!
- 如何制作HTML5 SVG描边文字
- IB客座主编(三):西门子(中国)有限公司工业业务领域楼宇科技集团杜明轩(Christophe de Maistre)先生...
- mysql的建库建表语句_SQL语句(建库、建表、修改语句)
- mysql killing slave_MySQL Slave 触发 oom-killer解决方法
- Oracle Goldengate在HP平台裸设备文件系统OGG-01028处理
- python----运行机制
- 如何把SWF转为PDF文件
- 大数据在人力资源管理当中的应用
- ps制作公章教程,沿着圆圈打字,斑驳效果
- php pandoc,Pandoc 标记语言转化工具
- 旧稿 - 我与张树新共事创业的年代 - 张树新马云
- namenode启动报错:There appears to be a gap in the edit log. We expected txid 1, but got txid 16
- 【已解决】Failed to discover available identity versions when contacting http://controller:5000/v3.
- fedora34 不显示桌面图标
- 信息系统安全概述(课程笔记)
- C语言基础代码合集 | 十进制转化为二进制