Ratio(P1079)

【AI大模型应用开发】【项目实战】11.基于BERT+P-Tuning方式实现新零售行业决策评价系统 本文介绍了基于BERT+P-Tuning的小样本文本分类方法在电商评论分析中的应用。针对标注数据稀缺问题,P-Tuning通过可学习模板替代人工模板,解决了传统PET方法的不稳定性。项目使用PyTorch和Transformers库,构建了包含数据处理、模型训练、评估和预测的完整流程。核心步骤包括:1)数据预处理,将评论与模板拼接并转换为模型输入;2)定义Verbalizer类实现标签映射;3)使用MLM损失函数优化模型;4)评估指标计算。实验表明,该方法在少量标注数据下仍能取得较好分类效果 阅读详情

这种题要想到的细节比较多,所以要先有一个清析的思路,特别是边界最容易出问题,


#include<iostream>
#include<cstdio>
#include<cstring> 
#include<ctype.h>
#include<vector>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<string>
#include<map>
#include<stack>
using namespace std; 


int gcd(int big,int small)
{
	if (big<small)
		swap(big,small);
	if (big%small==0)
		return small;
	return gcd(small,big%small);
}

int  get(long double a,long double b,int k,long double div)
{
	int  i,j;
	long double c=a/b;
	i=1;
	j=(int)(a/b)+10;
	j*=a;

	while (i<j)
	{
		
		int m=i+(j-i)/2;
		if (fabs((long double)m/(long double)k-c)<div)
			return m;
		else if (fabs((long double)j/(long double)k - c)<fabs((long double)i/(long double)k-c))
			i=m+1;
		else
			j=m-1;
	}
	//cout<<i<<endl;
	return i;
}

int main()
{
	int i,j,k;

	int a,b;
	//cout<<377.0/227.0-749.0/451.0<<' '<<93.0/56.0-749.0/451.0<<endl;
	long double c;
	while (cin>>a>>b)
	{
		int g=gcd(a,b);
		a/=g;
		b/=g;
		long double fa=a;
		long double fb=b;
		long double div=1.0;
		c=fa/fb;
		//cout<<c<<endl;
		long double aa,bb;
			
		div=100000000;
		for (i=1;i<(int)c+10;i++)
		{
			if (div>=fabs((double)i-c))
			{
				div=fabs((double)i-c);
				j=i;
			}
		}
		printf("%d/1\n",j);  //第一个单独判断最好,不然后面混合在一起容易混。

		for (i=2;i<b;i++)
		{	
			j=get(fa,fb,i,div);
			aa=j;
			bb=i;
			
	
			if (div>fabs((aa)/(bb)-c))
			{//cout<<aa/bb<<' '<<div<<endl;
				div=fabs((aa)/(bb)-c);
				printf("%d/%d\n",j,i);
				//cout<<div<<' '<<fabs(aa/bb-c)<<endl;
			}
		
		}
		//if (n>1)
		printf("%d/%d\n\n",a,b);
	}

	return 0;
}


Ratio
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 3521 Accepted: 1302

Description

If you ever see a televised report on stock market activity, you'll hear the anchorperson say something like ``Gainers outnumbered losers 14 to 9,'' which means that for every 14 stocks that increased in value that day, approximately 9 other stocks declined in value. Often, as you hear that, you'll see on the screen something like this:
Gainers 1498
Losers 902

As a person with a head for numbers, you'll notice that the anchorperson could have said ``Gainers outnumbered losers 5 to 3'', which is a more accurate approximation to what really happened. After all, the exact ratio of winners to losers is (to the nearest millionth) 1.660754, and he reported a ratio of 14 to 9, which is 1.555555, for an error of 0.105199; he could have said ``5 to 3'', and introduced an error of only 1.666667-1.660754=0.005913. The estimate ``5 to 3'' is not as accurate as ``1498 to 902'' of course; evidently, another goal is to use small integers to express the ratio. So, why did the anchorperson say ``14 to 9?'' Because his algorithm is to lop off the last two digits of each number and use those as the approximate ratio.

What the anchorman needs is a list of rational approximations of increasing accuracy, so that he can pick one to read on the air. Specifically, he needs a sequence {a_1, a_2, ..., a_n} where a_1 is a rational number with denominator 1 that most exactly matches the true ratio of winners to losers (rounding up in case of ties), a_{i+1} is the rational number with least denominator that provides a more accurate approximation than a_i, and a_n is the exact ratio, expressed with the least possible denominator. Given this sequence, the anchorperson can decide which ratio gives the best tradeoff between accuracy and simplicity.

For example, if 5 stocks rose in price and 4 fell, the best approximation with denominator 1 is 1/1; that is, for every stock that fell, about one rose. This answer differs from the exact answer by 0.25 (1.0 vs 1.25). The best approximations with two in the denominator are 2/2 and 3/2, but neither is an improvement on the ratio 1/1, so neither would be considered. The best approximation with three in the denominator 4/3, is more accurate than any seen so far, so it is one that should be reported. Finally, of course, 5/4 is exactly the ratio, and so it is the last number reported in the sequence.

Can you automate this process and help the anchorpeople?

Input

input contains several pairs of positive integers. Each pair is on a line by itself, beginning in the first column and with a space between the two numbers. The first number of a pair is the number of gaining stocks for the day, and the second number is the number of losing stocks for the day. The total number of stocks never exceeds 5000.

Output

For each input pair, the standard output should contain a series of approximations to the ratio of gainers to losers. The first approximation has '1' as denominator, and the last is exactly the ratio of gainers to losers, expressed as a fraction with least possible denominator. The approximations in between are increasingly accurate and have increasing denominators, as described above.
The approximations for a pair are printed one to a line, beginning in column one, with the numerator and denominator of an approximation separated by a slash (``/''). A blank line separates one sequence of approximations from another.

Sample Input

5 4 
1498 902 

Sample Output

1/1 
4/3 
5/4 

2/1 
3/2 
5/3 
48/29 
53/32 
58/35 
63/38 
68/41 
73/44 
78/47 
83/50 
88/53 
93/56 
377/227 
470/283 
563/339 
656/395 
749/451

Source



Qwen2-72B中文实战指南:从分词器陷阱到32K真长文本部署 大语言模型的中文能力并非单纯依赖参数规模,而是由分词器设计、位置编码机制、指令微调数据分布与推理优化共同决定。Qwen2-72B之所以在政务、法律、教育等高要求中文场景表现突出,关键在于其原生中文tokenization策略、RoPE基频增强的32K上下文稳定性,以及高达68%中文指令微调占比带来的强事实遵循性。相比Llama-3和Mixtral等通用架构模型,它在中文语义单元识别(如‘一网通办’整体切分)、长文本关键信息召回(92%+)、指令格式严格度(96.7%)等方面形成代际优势。本文聚焦真实工程落地 阅读详情

相关推荐

【AI大模型应用开发】【项目实战】10.基于BERT+PET方式实现新零售行业决策评价系统

本项目基于电商平台用户评论数据,采用BERT+PET(Pattern-Exploiting Training)方法实现评论文本分类。PET通过设计提示模板将分类任务转化为完形填空任务,充分利用预训练语言模型的知识,在小样本场景下表现优异。项目实现了数据预处理、模型训练评估及预测全流程,包括模板构造、标签映射、损失计算等关键模块。实验结果表明,该方法在验证集上达到F1值0.76,为电商平台快速分析用户偏好、改进产品服务提供了有效技术方案,同时为个性化推荐系统奠定了基础。

资深系统架构,深耕高并发研发与 AI 大模型工程化落地。技术栈以 Python (AI/NLP/RAG/Agent) 与 Golang (高并发架构) 为双核心,兼具 PHP 大型应用经验。专注算法落地、复杂系统设计及团队技术赋能 207

UVA 654 - Ratio(枚举)

Ratio  If you ever see a televised report on stock market activity, you'll hear the anchorperson say something like ``Gainers outnumbered losers 14 to 9,'' which means that for every 14 s

Remilia's 2618

【信息科学与工程学】计算机科学与自动化——第六十六篇 算子篇 第一章 通用算子01 多模态数据(图形/图像/文本/语音)中推断人类内在状态、策略、动机和利益的算法算子知识库

编号领域算法/方法算子名称算子的数学方程式/表达复杂度 (示例)关联知识11量子场论正则量子化产生/湮灭算符对易关系: [â_p, â†_q] = δ⁽³⁾(p​ - q)应用于态空间,计算复杂度取决于截断福克空间,粒子数表象,二次量子化12统计力学蒙特卡洛模拟马尔可夫链转移算子T(s → s‘) :满足细致平衡条件 π(s)T(s→s’)=π(s‘)T(s’→s)收敛到平衡分布需 ~O(τ), τ为相关时间细致平衡,Metropolis-Hastings准则,重要性采样13电磁学边界元法单层势/双层势算子

weixin_49199313的博客 315

POJ 1079 : Ratio - 分数逼近

题意:题意一目了然吧~分母从1到max,进行逼近解法一:#include#include#includeusing namespace std;int main(){ int i,p,q,pt,a,b; while(~scanf("%d%d",&a,&b)){ p=1; q=0; for(i=1;i pt=(int)((double)(i*a)/(double)b+0.5); if(

Booky的专栏 995

【信息科学与工程学】【通信工程】第一百九十一篇 路由器体系结构03

编号类型领域问题详细的数学分析(逐步推理)参数列表(表达式 / 数值范围 / 边界 / 测量)关联知识839DCI演进 · 收敛DCI 2030 年三大技术收敛方向步骤1:方向一:IPoDWDM 成为绝对主流(Omdia 2027 59% → 2030 80%+),OTN 退化为 OLS 纯光层。步骤2:方向二:800ZR+ 取代 400ZR 成为主力速率,PCS 使 800G 达 600–1000km。步骤3:方向三:AI 集群 DCI 催生 1.6T/3.2T 超短距(<10km)相干模块(OSFP-X

weixin_49199313的博客 895

【信息科学与工程学】【通信工程】第七十六篇 网络解决方案设计03

继续围绕智算中心相关的组网设计、光路设计、波分设计、OTN设备、交换机设备、组网拓扑、网络操作系统、业务区/管理区/存储区、光设计、租户设计、电磁设计、队列设计、QoS设计、调度设计、组合设计等领域。: 若Tpxe​=2min,Tos_install​=5min,Tagent​=0.5min,Tconfig​=0.5min,则Tready​=8min。: 若N=2000,Ms​=2,Nstorage​=128,Mss​=2,则Nip​=2000×2+128×2=4256,需要/20子网。

weixin_49199313的博客 211

汽车图像缩放技术:从YUV格式到TI Jacinto RSZ硬件实现

图像缩放是计算机视觉与多媒体处理中的基础技术,其核心原理是通过像素重采样与插值算法改变图像分辨率。在实时视频处理领域,双三次卷积插值与线性插值是两种主流方法,前者通过4x4邻域加权计算实现高质量放大,后者则通过线性加权实现快速处理。这项技术的工程价值在于平衡画质、实时性与功耗,尤其在汽车座舱系统等嵌入式场景中至关重要。YUV格式因其高效的色度采样(如4:2:2与4:2:0)成为视频处理标准,能有效降低带宽需求。本文以德州仪器Jacinto 6 Plus的RSZ模块为例,深入解析其双引擎架构、寄存器配置及YU

weixin_33895657的博客 492

【信息科学与工程学】【数据科学】数据科学领域——第三篇 数学08 几何学00总篇

编号英文名称中文名称简要说明/归属1Foundations of Geometry几何基础公理化方法, Hilbert《几何基础》2Euclidean Geometry (Synthetic)欧几里得几何(综合法)《几何原本》传统3Analytic Geometry解析几何坐标方法, Descartes, Fermat4Plane Geometry平面几何三角形、圆、共点共线等经典问题5Solid Geometry立体几何三维空间中的图形与度量6Non-Euclidean Geometry非欧几何平行公设不

weixin_49199313的博客 240

c语言实现单词逆序 单词内部不逆序

c语言实现单词逆序 单词内部不逆序 比如: i am from shanghai 变为 shanghai from am i

【信息科学与工程学】信息科学领域——第一百三十五篇 射频/天线03

按照之前的模式,继续补充961-970,保持领域覆盖均衡,延续材料、几何、拓扑、电磁、组网、信号、脉冲、数据传输、信号采集、信号编解码十个方向,每个方向至少一题,可以适当穿插一些之前未充分覆盖的子领域(比如材料还可以做钙钛矿、MXene等;我们收到了用户要求继续补充的问题,需要新增编号,并关注射频/天线的材料领域、几何、拓扑、电磁、组网、信号、脉冲、数据传输、信号采集、信号编解码领域。注意保持表格格式一致,内容涵盖射频/天线领域的各种子领域,包括6G、5G、脉冲、波/函数、组合、组网、射频设计等。

weixin_49199313的博客 280

西工大noj答案完整版.doc

西北工业大学NOJC程序设计习题答案(非本人制作,侵删) 1.“1“的传奇 2.A+B 3.A+BⅡ 4.AB 5.ACKERMAN 6.Arithmetic Progressions 7.Bee 8.Checksum algorithm 9.Coin Test 10.Dexter need help 11.Double 12.Easy problem 13.Favorite number 14.Graveyard 15.Hailstone 16.Hanoi Ⅱ 17.Houseboat 18.Music Composer 19.Redistribute wealth 20.Road trip 21.Scoring 22.Specialized Numbers 23.Sticks 24.Sum of Consecutive 25.Symmetric Sort 26.The Clock 27.The Ratio of gainers to losers 28.VOL大学乒乓球比赛 29.毕业设计论文打印 30.边沿与内芯的差 31.不会吧,又是A+B 32.不屈的小蜗 33.操场训练 34.插入链表节点 35.插入排序 36.插入字符 37.成绩表计算 38.成绩转换 39.出租车费 40.除法 41.创建与遍历职工链表 42.大数乘法 43.大数除法 44.大数加法 45.单词频次 46.迭代求根 47.多项式的猜想 48.二分查找 49.二分求根 50.发工资的日子 51.方差 52.分离单词 53.分数拆分 54.分数化小数 55.分数加减法 56.复数 57.高低交换 58.公园喷水器 59.韩信点兵 60.行程编码压缩算法 61.合并字符串 62.猴子分桃 63.火车站 64.获取指定二进制位 65.积分计算 66.级数和 67.计算A+B 68.计算PI 69.计算π 70.计算成绩 71.计算完全数 72.检测位图长宽 73.检查图像文件格式 74.奖金发放 75.阶乘合计 76.解不等式 77.精确幂乘 78.恐怖水母 79.快速排序 80.粒子裂变 81.链表动态增长或缩短 82.链表节点删除 83.两个整数之间所有的素数 84.路痴 85.冒泡排序 86.你会存钱吗 87.逆序整数 88.排列 89.排列分析 90.平均值函数 91.奇特的分数数列 92.求建筑高度 93.区间内素数 94.三点顺序 95.山迪的麻烦 96.删除字符 97.是该年的第几天 98.是该年的第几天? 99.数据加密 100.搜索字符 101.所有素数 102.探索合数世纪 103.特殊要求的字符串 104.特殊整数 105.完全数 106.王的对抗 107.危险的组合 108.文件比较 109.文章统计 110.五猴分桃 111.小型数据库 112.幸运儿 113.幸运数字”7“ 114.选择排序 115.寻找规律 116.循环移位 117.延伸的卡片 118.羊羊聚会 119.一维数组”赋值“ 120.一维数组”加法“ 121.勇闯天涯 122.右上角 123.右下角 124.圆及圆球等的相关计算 125.圆及圆球等相关计算 126.程序员添加行号 127.找出数字 128.找幸运数 129.找最大数 130.整数位数 131.重组字符串 132.子序列的和 133.子字符串替换 134.自然数立方的乐趣 135.字符串比较 136.字符串复制 137.字符串加密编码 138.字符串逆序 139.字符串排序 140.字符串替换 141.字符串左中右 142.组合数 143.最次方数 144.最大乘积 145.最大整数 146.最小整数 147.最长回文子串 148.左上角 149.左下角

西北工业大学材基习题.doc

材聊基础基习题.doc 考研 西北工业大学

西工大C语言大作业习题答案

西工大C语言大作业习题答案

C语言循环练习题.doc

这是一些初学者可以尝试的C语言编程练习题,如果是新手的话,大家可以主动尝试着做一下,有益于大家C语言编程的进步,大家加油!!不会的可以一起交流哦!

poj 第九季 第十季

Dexter need help;Checksum algorithm;Graveyard;Hanoi II;Houseboat;Sum of Consecutive;Arithmetic Progressions;Redistribute wealth;Scoring;Specialized Numbers;操场训练;最长回文子串;寻找规律;公园喷水器;阶乘合计;不屈的小蜗;Hailstone;The Ratio of gainers to losers

西北工业大学软件技术实验答案包括大作业1

西北工业大学软件技术实验答案包括大作业 以及10个实验答案 计算器

【R-CNN系列目标检测】(7)SSD算法

【1】SSD(Single Shot MultiBox Detector)算法可以理解为 YOLO + Faster R-CNN 的进化方法。

zizi7的专栏 1956

冒泡合并快速排序 、顺序二分搜索

算法设计与分析,冒泡排序与合并排序的时间复杂度比较 顺序搜索与二分搜索时间复杂度比较 合并排序与快速排序时间复杂度比较(时间复杂度是以比较次数来衡量的)

上一篇: Gone Fishing(p1042)
下一篇: Wooden Stichs(P1065)
jiangjiashi
博客等级 码龄17年 41粉丝 319原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值