POJ 3262 Protecting the Flowers(贪心)

Vue3 - Element Plus 树形表格组件 el-table 一键全部展开折叠功能,支持动态数据及懒加载点击父级才去请求的场景,Tree树状表格每行带有children的表格全部收起和折叠! vue3,element-plus,表格Table组件,el-table,怎样一键展开/收起,一键展开或折叠树形表格,如何通过按钮来实现全部展开,不生效,一键折叠或展开表格,表格children嵌套,带有子集,多级表格,懒加载,动态数据,table表格的children通过后端请求过来的怎么一键展开请求数据呢,表格如何一键展开和折叠,怎么使用,教程,树形数据table全部展开和折叠,一键展开或折叠树形表格,点击展开接口获取数据,toggleRowExpansion,树形表格懒加载与全部折叠,深层多级,复杂, 阅读详情

Language:
Protecting the Flowers
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 4942 Accepted: 1973

Description

Farmer John went to cut some wood and left N (2 ≤ N ≤ 100,000) cows eating the grass, as usual. When he returned, he found to his horror that the cluster of cows was in his garden eating his beautiful flowers. Wanting to minimize the subsequent damage, FJ decided to take immediate action and transport each cow back to its own barn.

Each cow i is at a location that is Ti minutes (1 ≤ Ti ≤ 2,000,000) away from its own barn. Furthermore, while waiting for transport, she destroys Di (1 ≤ Di ≤ 100) flowers per minute. No matter how hard he tries, FJ can only transport one cow at a time back to her barn. Moving cow i to its barn requires 2 × Ti minutes (Ti to get there and Ti to return). FJ starts at the flower patch, transports the cow to its barn, and then walks back to the flowers, taking no extra time to get to the next cow that needs transport.

Write a program to determine the order in which FJ should pick up the cows so that the total number of flowers destroyed is minimized.

Input

Line 1: A single integer  N 
Lines 2.. N+1: Each line contains two space-separated integers,  Ti and  Di, that describe a single cow's characteristics

Output

Line 1: A single integer that is the minimum number of destroyed flowers

Sample Input

6
3 1
2 5
2 3
3 2
4 1
1 6

Sample Output

86

Hint

FJ returns the cows in the following order: 6, 2, 3, 4, 1, 5. While he is transporting cow 6 to the barn, the others destroy 24 flowers; next he will take cow 2, losing 28 more of his beautiful flora. For the cows 3, 4, 1 he loses 16, 12, and 6 flowers respectively. When he picks cow 5 there are no more cows damaging the flowers, so the loss for that cow is zero. The total flowers lost this way is 24 + 28 + 16 + 12 + 6 = 86.

Source



#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>


#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)

#define eps 1e-8
typedef __int64 ll;

#define fre(i,a,b)  for(i = a; i <b; i++)
#define free(i,b,a) for(i = b; i >= a;i--)
#define mem(t, v)   memset ((t) , v, sizeof(t))
#define ssf(n)      scanf("%s", n)
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pf          printf
#define bug         pf("Hi\n")

using namespace std;

#define INF 0x3f3f3f3f
#define N 100005

struct stud{
   ll x,t;
   bool operator <(const stud b)const
   {
   	  return (ll)(x*b.t)>(ll)(b.x*t);
   }
}f[N];

int main()
{
	int i,j,n;
	ll ans;
	while(~sf(n))
	{
		for(i=0;i<n;i++)
			{
			 scanf("%I64d%I64d",&f[i].t,&f[i].x);
			 f[i].t*=2;
			}
		sort(f,f+n);
		ans=0;
		ll temp=0;
		for(i=0;i<n;i++)
		{
			ans+=temp*f[i].x;
			temp+=f[i].t;
		}
      pf("%I64d\n",ans);
	}
  return 0;
}







Java代码变更影响分析:从静态解析到动态调用图的实战全链路 本文介绍了Java代码提交影响分析的核心原理与实现方法。主要内容包括:1)静态分析技术,通过JavaParser解析AST构建调用图,记录类与方法间的调用关系;2)动态分析技术,使用ByteBuddy进行字节码增强,捕获运行时调用路径;3)JCCI工具实现,结合javalang、unidiff等技术分析代码改动影响,并将结果存储到SQLite数据库。文章提供了完整的代码示例,展示了从AST解析、动态调用跟踪到实际工具应用的完整技术栈,为代码变更影响分析提供了实用解决方案。 阅读详情

相关推荐

CTFHUB------XSS反射型(WP)

文章目录前言XSS测试平台 前言 一开始我直接在上面写js脚本发现出错,最后发现只能通过下面的输入框来执行XSS测试,于是我们只能用XSS测试平台解决问题 XSS测试平台 注册一个XSS测试平台 这里随便填写 勾选默认模块就够了,点击下一步 这时会出现一个找个将代码复制 拼接到网站后缀name后面,点击send 这时平台会收到一个记录点开即可 得到flag ...

Y4tacker的博客 1万+

Protecting the Flowers 牛客题解

Protecting the Flowers 题目链接:传送门 链接:https://ac.nowcoder.com/acm/problem/25043 来源:牛客网 Farmer John went to cut some wood and left N (2 ≤ N ≤ 100,000) cows eating the grass, as usual. When he returned, he found to his horror that the cluster of cows was in his

sleepingartist的博客 509

Sourcetree与Gitee的完美协作:从身份验证到推送成功的全流程指南

本文提供了一份详细的Sourcetree与Gitee协作全流程指南,重点解决身份验证失败、Git版本配置及远端仓库设置等常见问题。通过分步讲解,帮助用户掌握从克隆、提交到成功推送的完整操作,并整合了使用个人访问令牌进行身份验证等关键热词信息,确保Windows与MacOS用户都能顺畅完成代码管理。

m2n3b4v5c6的博客 708

【题解】POJ 3262 Protecting the Flowers(贪心)

POJ 3262 Protecting the Flowers 原题 https://vjudge.net/problem/POJ-3262 农夫约翰去砍柴,像往常一样留下了N头(2≤N≤10万头)牛在吃草。当他回来时,他惊恐地发现那群牛正在他的花园里吃他美丽的花。为了尽量减少后续损失,FJ决定立即采取行动,将每头牛运回各自的谷仓。 每头牛i在距离它自己的谷仓Ti分钟(1≤Ti≤2,000,000)的位置。此外,在等待运输时,她每分钟会破坏Di(1≤Di≤100)朵花。无论他如何努力,FJ每次只能将一

bu_shushu的博客 1700

开源光标主题实战:从Moshi Monsters到自定义指针的完整指南

光标主题是操作系统个性化的重要组成部分,它通过替换系统默认指针图标来改变视觉交互体验。其原理在于操作系统允许用户自定义指针资源文件,这些文件定义了不同状态下的光标图像。从技术价值看,一套设计良好的光标主题不仅能提升桌面美观度,还能增强用户的情感连接和操作愉悦感,是低成本高回报的数字幸福感提升方案。在应用场景上,无论是开发者、设计师还是普通用户,都可以通过更换光标主题来个性化工作环境。本文以热门的Moshi Monsters开源光标项目为例,深入解析了光标主题的设计逻辑、系统适配方案以及二次创作方法,涵盖了W

weixin_30879833的博客 552

LVGL core theme主题管理(lv_theme.c)

如果打开宏,主题的初始化是在显示设备注册时完成的。整个themes的实现放在目录下面。这里一共有三套主题(basic、default和mono)可供选择或者参考。源码中默认对接的是 default 主题,所以在中,看到的是调用default主题的接口。也就是说,如果需要更换主题,把这里面的接口换掉就可以了。或者要重新做一套主题,参考这些实现修改也就可以了。虽说有三套主题,但逻辑流程是一样的。主要完成两个工作:构造lv_theme_t结构体和初始化默认样多备用(style_init函数内实现)。构造。....

Bigan(安)的博客 3410

Protecting the Flowers(POJ - 3262) 保护花 贪心

Farmer John went to cut some wood and left N (2 ≤ N ≤ 100,000) cows eating the grass, as usual. When he returned, he found to his horror that the cluster of cows was in his garden eating his beautiful flowers. Wanting to minimize the subsequent damage, FJ.

shiuxin的博客 537

ISMN数据处理

可批量下载,十分方便

m0_46268055的博客 1214

Protecting the flowers

时间限制:C / C ++ 1秒,其他语言2秒 空间限制:C / C ++ 32768K,其他语言65536K 64位IO格式:%lld 描述 农夫约翰去砍伐木头,照例让N(2≤N≤100,000)头牛吃草。当他返回时,他惊骇地发现,那群母牛在他的花园里吃着他美丽的花朵。为了最大程度地减少后续损失,FJ决定立即采取行动,将每头母牛运回自己的谷仓。 每头奶牛i的位置距离自己的牛舍都只有Ti分钟(1≤Ti≤2,000,000)。此外,在等待运输时,她每分钟会破坏Di(1≤Di≤100)花。无论他多么努力,FJ一

m0_53688600的博客 341

【Proteus仿真】用24C04与1602LCD设计的简易加密电子密码锁

【Proteus仿真】用24C04与1602LCD设计的简易加密电子密码锁

perseverance51博客 1121

YOLOv11改进 - C3k2融合 | C3k2融合CBSA 收缩 - 广播自注意力:轻量级设计实现高效特征压缩,优化处理效率 | NeurIPS 2025

本文介绍收缩 - 广播自注意力(CBSA)((Contract-and-Broadcast Self-Attention))机制,并将其集成到YOLOv11中。传统注意力机制存在黑盒难理解、计算复杂度高的问题,CBSA通过算法展开推导出本质上可解释且高效的注意力机制。它先从输入数据中选出少量代表性tokens,接着对代表进行收缩计算,再将结果广播给所有原始数据。该机制计算量线性增长,具有明确数学解释,还能统一多种注意力机制。我们将CBSA代码集成到YOLOv11的C3k2模块中。实验证明,改进后的YOLOv

魔改工程师的博客 851

牛客网 【每日一题】5月28日题目精讲 Protecting the Flowers

链接: 文章目录题目描述题意:题解:代码: 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K 64bit IO Format: %lld 题目描述 Farmer John went to cut some wood and left N (2 ≤ N ≤ 100,000) cows eating the grass, as usual. When he returned, he found to his horror that the cluster o

qq_35975367的博客 759

3D打印机控制系统设计:基于MATLAB的3D打印机运动学建模、轨迹规划和控制

控制实现:在控制实现中,需要将轨迹规划的结果转化为实际的控制指令,控制3D打印机按照规划的轨迹进行运动。3D打印机的运动学建模:3D打印机的运动学建模是指将3D打印机的机械结构、传动系统和运动控制部件等抽象成数学模型,以便于进行控制系统的设计和分析。轨迹规划:轨迹规划是指根据3D模型的几何形状和打印机的运动学模型,计算出打印机需要执行的运动轨迹,以便于实现所需的打印效果。控制实现:控制实现是指将轨迹规划的结果转化为控制指令,控制3D打印机按照规划的轨迹进行运动。

走向CTO的路上... 2473

POJ 3262 Protecting the Flowers 贪心 巧妙 G++

<span title="Description ">描述 农夫约翰去砍一些木头,留下N(2≤N≤100,000)牛吃草,像往常一样。当他回来时,他发现他的恐惧,群牛在他的花园里吃他美丽的花。<span title="Wanting to minimize the subsequent damage, FJ decided to take immediate action and t

woniupengpeng的专栏 317

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

POJ3262 Protecting the Flowers 【贪心】

Protecting the Flowers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4418   Accepted: 1785 Description Farmer John went to cut some wood and left N (2 ≤

长风的专栏 2314

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

POJ - 3262 Protecting the Flowers 贪心

传送门:POJ3262 题意:有n个牛在花园,每个牛在被赶走之前每秒吃Di个花朵。赶它回去要花的时间是Ti * 2。问最小损失花朵是多少。 思路:这个样例真是骚,想了好几种贪心方法都能过样例。。然而都是结果都是一样的wa。。 正解:考虑比率 Ti / Di,越小的越先赶走。 证明: 假设序列都由二元组组成,二元组是由D和T组成,那么对一个序列有相邻的两头牛是这样的 ....

WA是一笔财富 342

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

POJ 3262 Protecting the Flowers 贪心

题意很简单。 有n个牛在FJ的花园乱吃。 所以FJ要赶他们回牛棚。 每个牛在被赶走之前每秒吃Di个花朵。赶它回去FJ要花的时间是Ti。在被赶走的过程中牛就不能乱吃了 那么其实我第一感觉就是跟比率有关。 然后简略的证了一下。 假设序列都由二元组组成,二元组是由D和T组成,那么对一个序列有相邻的两头牛是这样的 ..........(a, b) ,(c, d)...........

水 3209

【POJ3262】Protecting the Flowers【贪心】

样例就是很直观的贪心... 但是直接按D再T的简单排序就WA了。 正确姿势如下: 考虑两头牛a和b,并且b的下标比a大,时间为Ta、Tb,每分钟吃的花为Da,Db。 若先a再b,则贡献为: W1 = Db * Ta * 2 若先b再a,则贡献为: W2 = Da * Tb * 2 要使第二种方案最优,则 W2 Da * Tb 这样排序下来就得到了拿走牛的顺序。

BraketBN 555

POJ3262 Protecting the Flowers(贪心)

Protecting the Flowers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4968   Accepted: 1985 Description Farmer John went to cut some wood and left N (2 ≤ N

GKHack's Blog 1282

[贪心] poj3262 Protecting the Flowers

Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5343 Accepted: 2105 DescriptionFarmer John went to cut some wood and left N (2 ≤ N ≤ 100,000) cows eating t

童凌的技术博客 561

Protecting the Flowers POJ - 3262 (贪心)

poj3262 FJ去砍树,然后和平时一样留了 N (2 ≤ N ≤ 100,000)头牛吃草。当他回来的时候,他发现奶牛们正在津津有味地吃着FJ种的美丽的花!为了减少后续伤害,FJ决定立即采取行动:运输每头牛回到自己的牛棚。 每只奶牛i在离牛棚Ti(1 ≤ Ti ≤ 2,000,000) 分钟路程的地方,每分钟吃掉Di(1 ≤ Di ≤ 100)朵花。FJ使尽浑身解数,也只能一次带回一头奶牛。...

xqx_Zi_yu 203

【贪心】POJ 3262 Protecting the Flowers

题目 Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Description Farmer John went to cut some wood and left N (2 ≤ N ≤ 100,000) cows eating the grass, as usual. W...

and1403的博客 379

POJ 3262 Protecting the Flowers 贪心比率

Description Farmer John went to cut some wood and left N (2 ≤ N ≤ 100,000) cows eating the grass, as usual. When he returned, he found to his horror that the cluster of cows was in his garden eating ...

RPG_Zero的博客 254

POJ3262 Protecting the Flowers【贪心】

Protecting the FlowersTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 8663 Accepted: 3501DescriptionFarmer John went to cut some wood and left N (2 ≤ N ≤ 100,000) cows eating the grass, as u...

海岛Blog 1042

poj3262 Protecting the Flowers(贪心)

Total Submissions: 10542 Accepted: 4289 Description Farmer John went to cut some wood and left N (2 ≤ N ≤ 100,000) cows eating the grass, as usual. When he returned, he found to his horror ...

一身清贫怎敢入繁华 351

Protecting the Flowers POJ 3262(贪心)

原题 题目链接 题目分析 有点难度的贪心题,首先考虑在相同时间t内怎么能使损失最少,可以这样来控制相同时间,设想一个子问题,如果只有两头牛,那最后结束时间肯定是一样的,这时候怎么使损失最少,就直接比较t1*d2和t2*d1就行了,如果是第一个小就选牛1,否则选牛二.扩展来讲,就是对所有牛排序,对于牛i,j,按照ti*dj<tj*di的规则规定优先权,最后只需要按顺序搬牛就行了...

dashengchong6303的博客 154
上一篇: POJ 3190 Stall Reservations(贪心)
下一篇: wust 1419 1419: We Love 01( 计数问题)
左眼皮跳跳~
博客等级 码龄13年 17粉丝 400原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值