hdu1160 FatMouse's Speed 最长上升子序列 LIS

kaggle-NeurIPS - Open Polymer Prediction 2025-0.069 本文摘要: 本研究基于多任务学习框架,开发了聚合物物理化学性质预测模型,能够根据SMILES字符串同步预测玻璃化转变温度(Tg)、分数游离体积(FFV)等5种关键性质。针对数据缺失率高、样本不均衡等挑战,采用"先补充后扩充"策略整合多源数据,并融合RDKit分子描述符、ChemBERTa语义特征和自编码器特征构建多维度表征。模型采用硬参数共享架构,结合动态加权损失函数和早停机制,在验证集上表现出色,其中密度预测R²达0.92。研究为聚合物性能的高通量预测提供了有效解决方案,对材料智能设计具有重要参考价值。 阅读详情

FatMouse's Speed

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13391    Accepted Submission(s): 5893
Special Judge


Problem Description
FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to take the data on a collection of mice and put as large a subset of this data as possible into a sequence so that the weights are increasing, but the speeds are decreasing.
 

Input
Input contains data for a bunch of mice, one mouse per line, terminated by end of file.

The data for a particular mouse will consist of a pair of integers: the first representing its size in grams and the second representing its speed in centimeters per second. Both integers are between 1 and 10000. The data in each test case will contain information for at most 1000 mice.

Two mice may have the same weight, the same speed, or even the same weight and speed. 
 

Output
Your program should output a sequence of lines of data; the first line should contain a number n; the remaining n lines should each contain a single positive integer (each one representing a mouse). If these n integers are m[1], m[2],..., m[n] then it must be the case that 

W[m[1]] < W[m[2]] < ... < W[m[n]]

and 

S[m[1]] > S[m[2]] > ... > S[m[n]]

In order for the answer to be correct, n should be as large as possible.
All inequalities are strict: weights must be strictly increasing, and speeds must be strictly decreasing. There may be many correct outputs for a given input, your program only needs to find one. 
 

Sample Input
6008 1300 6000 2100 500 2000 1000 4000 1100 3000 6000 2000 8000 1400 6000 1200 2000 1900
 

Sample Output
4 4 5 9 7
 


根据w升序排序,然后对s求最长递减子序列,注意保存每个元素的位置用于最后输出


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <stack>

using namespace std;

//w为体重,s为速度,pos为最初输入时在数组中的位置
struct node {
	int w, s, pos;
}a[1005];

bool cmp(node x, node y) {
	return x.w < y.w;
}

int ans[1005], pre[1005];

int main()
{
	int tw, ts, len;
	len = 0;
	while (~scanf("%d%d", &tw, &ts)) {
		a[len].w = tw;
		a[len].s = ts;
		a[len].pos = len; //记录每个node的在数组中原来的位置,注意此时是从0开始的,回来打印的时候要加1
		len++;
	}

	sort(a, a + len, cmp);  //根据w升序排列

	memset(ans, 0, sizeof(ans));
	ans[0] = 1; //初始化边界
	pre[0] = 0;

	int maxn, index, MAX = 1;  //最长递减子序列长度MAX初始为1
	for (int i = 1; i < len; i++) { //i: 1 -> len - 1
		maxn = 1;  //当前位置i的最长长度初始为1
		index = i; //初始的前驱为i自身
		//考察前面的最优解,即i之前到比a[i].s大的某个位置j的最长子序列长度
		for (int j = 0; j < i; j++) {
			//注意还要满足a[j].w < a[i].w,因为题目要求w严格递增
			if (a[j].s > a[i].s && a[j].w < a[i].w && ans[j] + 1 > maxn) {
				maxn = ans[j] + 1;
				MAX = max(MAX, maxn); //注意更新最大值
				index = j;
			}
		}
		//到当前位置的递减子序列长度最大值是maxn
		ans[i] = maxn;
		//记录前驱,用于最后输出
		pre[i] = index;
	}
	printf("%d\n", MAX);
	int dx;
	//查找最长递减子序列的最后一个元素的位置dx
	for (int i = 0; i < len; i++) {
		if (ans[i] == MAX) {
			dx = i;
			break;
		}
	}
	//用一个栈输出对前驱进行处理
	//注意最后要输出的是刚开始时在数组里的位置
	//当某个元素的前驱是自身的时候说明它就是最长子序列的第一个元素
	//跟并查集找父节点的思想如出一辙
	stack<int> s;
	do {
		s.push(a[dx].pos + 1);
		dx = pre[dx];
	} while (pre[dx] != dx);
	s.push(a[dx].pos + 1);

	//输出经栈处理过的顺序
	while (!s.empty()) {
		printf("%d\n", s.top());
		s.pop();
	}
	return 0;
}


1.为什么要学习MATLAB 学习MATLAB 阅读详情

相关推荐

【最长上升子序列LIS+路径记录】HDU-1160 FatMouse's Speed

注解 1、最长上升子序列的变形。先按照题目要求,根据weight升序和speed降序排序,然后是利用最长上升子序列LIS算法,找到符合要求的最长序列。 2、利用pre数组记录路径。 代码 #include <iostream> #include <algorithm> #include <cstring> using namespace std; st...

zhanggirlzhangboy的博客 531

Excel VBA+Adobe Acrobat Pro PDF发票识别全流程(附避坑指南)

本文详细介绍了如何利用Excel VBA与Adobe Acrobat Pro的API接口,构建一套企业级PDF发票智能识别与处理系统。内容涵盖从环境配置、核心文本提取原理、数据解析清洗到工程化脚本设计的全流程,并针对密码区干扰、不征税发票等常见问题提供避坑指南,旨在帮助财务人员和开发者实现高效、精准的财务数据处理自动化。

weixin_29207439的博客 356

HDU-1160 FatMouse's Speed

链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 题意:很多老鼠,每个老鼠有w(重量)和s(速度)两个属性,要求选一些老鼠,使他们的w严格递增且s严格递减,输出个数和老鼠的标号 思路:按照w升序排序,再求s的最长上升子序列(LIS),不过要注意的是本题还要求记录路径,为了方便,我用的是O(n^2)的路径存储算法我不会nlogn的,这里...

weixin_30709809的博客 112

别再为数据发愁:5分钟理解事件相机原理,并自己动手生成事件图像

本文深入浅出地解析了事件相机的工作原理,并提供了从静态图像生成事件数据的实用方法。通过Python代码示例,读者可以快速掌握如何模拟事件相机的输出,应用于机器人导航、自动驾驶等领域,解决数据获取难题。

weixin_31458015的博客 308

DDR4 IP的用户接口

DDR4 IP核用户接口

bowen_wener的博客 1935

HDU1160(FatMouse's Speed)

题目入口 题意 题目耐心一点看,大概意思就是说每一行给出一只老鼠的体重和速度,然后证明题目中的一个结论:体重增重,速度减慢,很明显就是一个LIS问题的变种。然后输出“最长上升子序列的长度”,以体重作为第一排序标准,然后再以速度做为第二排序标准,体重大的放在后面,速度大的放在前面。 思路 因为题目要输出最长上升子序列输入时候的序号,输入数据的体重和速度都是无序的,要求最长的上升子序列那么需要对这个...

weixin_43808717的博客 317

利用 IP 中的集成调试功能来调试 PCI Express 链接训练问题

JTAG Debugger”和“In-system IBERT”功能结合在一起即可提供即时信息,用于判断链接训练问题的可能原因。“test_rd.tcl”文件可读取 BRAM 中存储的调试数据,并输出 *.dat 文件,如下所示。同样,您可能看到某一箭头旁的数字较大,表明可能存在不稳定的链接。要采集 PCIe 链接眼图,请在 IP 配置 GUI 的“Add. Debug Options”选项卡中选择“启用 In-System IBERT (Enable In-System IBERT)”选项。

qq_43416206的博客 549

HDU 1160 FatMouse's Speed 最长上升子序列,重拾DP

最简单的DP。。。并且在被提示了考虑dp[i]为i结尾的子序列的最长子序列,各种姿势还是没做出来。。 把体重降序排列,就变成了求速度的最长上升子序列,输出正是按次要求,也不用再倒序; n n^2复杂度足以;但是LIS有nlogn的算法:点击打开链接 /* *********************************************** Author :angon

卡尔 781

Qualcomm AI Engine Direct SDK(QNN)的使用介绍

Qualcomm AI Engine Direct SDK,高通新的AI模型推理框架,又名QNN,为AI开发提供统一API的底层框架。通过这个SDK,可以在高通的 CPU/GPU和HTP上对AI模型进行性能加速。2.Qualcomm AI Engine Direct SDK的公开英文文档。1.Qualcomm AI Engine Direct SDK的下载和安装。

u013250861的博客 6989

基于滤波反投影的图像重建算法matlab仿真

基于滤波反投影的图像重建算法是一种用于医学影像重建的计算机辅助技术。该算法可以从投影数据中重建出高质量的三维图像,被广泛应用于医学影像学、CT、PET等领域。本文将详细介绍基于滤波反投影的图像重建算法的原理、步骤和应用。一、原理介绍基于滤波反投影的图像重建算法基于X射线CT成像原理,它的主要思想是通过对投影数据进行处理,反推出被成像物体的三维形状。其核心原理是投影数据与目标物体之间的线性关系,即通过估计目标物体的吸收率来计算投影数据的变化,从而反推出目标物体的三维形状。

平时工作较为繁忙,私信消息一般晚上回复,谢谢大家~~ 393

HDU - 1160 FatMouse's Speed

input: 6008 1300 6000 2100 500 2000 1000 4000 1100 3000 6000 2000 8000 1400 6000 1200 2000 1900    output: 4 4 5 9 7    题目大意: 有cnt组数据,每组有体重和速度两个值,求其最长上升子序列并打印出他...

DDDDDDDDDD4444444444的博客 185

【ArcGIS微课1000例】0068:ArcGIS加载world imagery高清卫星影像教程

本文介绍了如何在ArcGIS中加载World Imagery高清卫星影像作为谷歌影像的替代方案。通过添加ArcGIS Server并输入在线图集URL(https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer),即可连接并预览包含中国影像、青海湖、东方明珠等全球高清卫星图。该教程提供了详细的操作步骤图示,帮助用户快速获取优质底图数据,适用于地理信息分析和可视化应用。

智慧空间实验室 5460

HDU 1160 FatMouse's Speed (最长上升子序列+路径输出)

Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to take the data on a collection of mice and put as large a subset of this data as p

←_← 449

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

HDU1160 FatMouse's Speed(lis)

FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 20657    Accepted Submission(s): 9154Special Judge   Problem Description Fa...

fighting_yifeng的博客 251

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

Hdu 1160 FatMouse's Speed (LIS路径输出)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 题意:给出n个老鼠的重量和速度值(先重量后速度),要求给出一个最长的排列,其中,前一只老鼠的重量严格小于后一只老鼠,而它的速度要严格大于后一只老鼠。排列可能有多种,只要求出一种就可以了。 思路:排序后转化为最长上升子列。 忽略了可能有多种正确排列,白白调试好久…… #include #

whyorwhnt的专栏 967

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

HDU 1160 FatMouse's Speed

简单DP,最长上升子序列。先对W排序,然后对S做做LIS #include<cstdio> #include<cstring> #include<cmath> #include<stack> #include<vector> #include<algorithm> using namespace std; ...

weixin_34240520的博客 68

hdu1160_FatMouse's Speed 最大上升子序列

FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14806    Accepted Submission(s): 6521 Special Judge Problem Descript

路漫漫其修远兮 239

HDU 1160 FatMouse's Speed (记录路径的最长上升子序列)

题意 很多肥老鼠认为,长的越肥,奔跑速度就越快,为了反驳这个观点,你现在需要对老鼠的体重和速度进行研究,你要在老鼠序列中找出一个子序列,使得老鼠的体重在增加,但是速度却在减慢 很多肥老鼠认为,长的越肥,奔跑速度就越快,为了反驳这个观点,你现在需要对老鼠的体重和速度进行研究,你要在老鼠序列中找出一个子序列,使得老鼠的体重在增加,但是速度却在减慢 Input 输入以eof结束。 输入中每行有...

EnjoyingAC的博客 383

HDU-1160-FatMouse's Speed(线性DP,LIS)

FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 20784    Accepted Submission(s): 9220Special Judge Problem Description FatM...

随便写写 279

HDU1160 FatMouse's Speed(最长上升子串)

题目链接:http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=3&amp;sectionid=2&amp;problemid=4 题目大意:按体重上升,速度下降排序后,提取符合条件的最长子序列,以证明体重越高,速度越慢 参考链接:https://blog.csdn.net/liyongfan152/article/detail...

weixin_42374305的博客 207

HDU - 1160FatMouse's Speed(最长上升子序列+输出顺序)

FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to take the data on a collection of mice and put as large a subset of this data as possible into a sequence

T__TSZ的博客 537

FatMouse's Speed Hdu1160 动态规划 EOF(Ubuntu 下codeblocks 按 Ctrl+D)

FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 16982    Accepted Submission(s): 7511 Special Judge Problem Description

米兰的小科比 595

hdu4283 You Are the One 区间dp 记忆化搜索or递推

You Are the One Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3032    Accepted Submission(s): 1352 Problem Description   The TV s

EventQueue的博客 1795

hdu1503 Advanced Fruits

Advanced Fruits Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2300    Accepted Submission(s): 1169 Special Judge Problem Description

EventQueue的博客 916

hdu5904 LCIS dp

LCIS Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 645    Accepted Submission(s): 300 Problem Description Alex has two sequences 

EventQueue的博客 671
上一篇: poj2249 Binomial Showdown 求组合数
下一篇: hdu1224 Free DIY Tour DFS或者dp
Daemoonn
博客等级 码龄11年 42粉丝 198原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址