20年秋季 7-1 Panda and PP Milk (20 分)

7-1 Panda and PP Milk (20 分)

panda.jpg

PP milk (盆盆奶)is Pandas' favorite. They would line up to enjoy it as show in the picture. On the other hand, they could drink in peace only if they believe that the amount of PP milk is fairly distributed, that is, fatter panda can have more milk, and the ones with equal weight may have the same amount. Since they are lined up, each panda can only compare with its neighbor(s), and if it thinks this is unfair, the panda would fight with its neighbor.

Given that the minimum amount of milk a panda must drink is 200 ml. It is only when another bowl of milk is at least 100 ml more than its own that a panda can sense the difference.

Now given the weights of a line of pandas, your job is to help the breeder(饲养员)to decide the minimum total amount of milk that he/she must prepare, provided that the pandas are lined up in the given order.

Input Specification:

Each input file contains one test case. For each case, first a positive integer n (≤10​4​​) is given as the number of pandas. Then in the next line, n positive integers are given as the weights (in kg) of the pandas, each no more than 200. the numbers are separated by spaces.

Output Specification:

For each test case, print in a line the minimum total amount of milk that the breeder must prepare, to make sure that all the pandas can drink in peace.

Sample Input:

10
180 160 100 150 145 142 138 138 138 140

Sample Output:

3000

Hint:

The distribution of milk is the following: 

400 300 200 500 400 300 200 200 200 300

这道题读了好久没弄懂,还是小美女帮我理清思路了。

题目大意:

一排熊猫在喝“盆盆奶”,他们不打架的规则是:体重不同的熊猫喝的牛奶可以不同,但是体重相同的熊猫必须一样多。胖的熊猫喝的可以多一些。

思路:

①从左往右遍历:

第一个设为200ml,如果第二个比他多就+100,相等就相同,比他少就直接200;

②从右往左遍历:

倒数第一个设为200ml,同理;

③从左往右遍历取max:

这样,就可以保证所有的熊猫既不会和左边的打起来,也不会和右边的打起来。

代码:

// 03.12 20:00
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 10010;
struct Panda {
	int weight;
	int m1; // 从左到右
	int m2; // 从右到左
}panda[maxn];

int main() {
	freopen("input.txt", "r", stdin);
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &panda[i].weight);
	}
	// 从左到右
	panda[0].m1 = 200;
	for (int i = 1; i < n; i++) {
		if (panda[i].weight > panda[i - 1].weight)
			panda[i].m1 = panda[i - 1].m1 + 100;
		else if (panda[i].weight == panda[i - 1].weight)
			panda[i].m1 = panda[i - 1].m1;
		else
			panda[i].m1 = 200;
	}
	// 从右到左
	panda[n - 1].m2 = 200;
	for (int i = n - 2; i >= 0; i--) {
		if (panda[i].weight > panda[i + 1].weight)
			panda[i].m1 = panda[i + 1].m1 + 100;
		else if (panda[i].weight == panda[i + 1].weight)
			panda[i].m1 = panda[i + 1].m1;
		else
			panda[i].m1 = 200;
	}
	// 取两个序列的max,并累加到总牛奶sum
	int sum = 0;
	for (int i = 0; i < n; i++){
		int ans = (panda[i].m1 > panda[i].m2) ? panda[i].m1 : panda[i].m2;
		sum += ans;
	}
	printf("%d\n", sum);
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
usb通用加密狗型号查看工具,读狗插件,部 加密狗/加密锁 VID识别加密狗具体型号USB\\VID_096E&PID;_0001 飞天诚信(ftsafe) 飞天4有驱型 加密锁 ROCKEY 4 Rockey4 R4HID\\VID_096E&PID;_0006 飞天诚信(ftsafe) 飞天4无驱型 加密锁 rockey 4 nd ROCKEY4ND R4ndUSB\\VID_096E&PID;_0201 飞天诚信(ftsafe) 飞天2无驱型 加密锁 rockey 2 ROCKEY2 R2USB\\VID_096E&PID;_0304 坚石诚信(Rockey) ET199 Token ET199USB\\VID_096E&PID;_0303 坚石诚信(Rockey) ET99 Token ET99USB\\VID_096E&PID;_0201 飞天诚信(FTSafe) Rockey 2 加密狗,无驱型USB\\VID_096E&PID;_0202 飞天诚信(FTSafe) Rockey 3 智能狗,无驱型USB\\VID_096E&PID;_0205 飞天诚信(FTSafe) Rockey 1 智能狗,无驱型USB\\VID_096E&PID;_0207 飞天诚信(FTSafe) Rockey 1 智慧型,无驱型USB\\VID_096E&PID;_0209 坚石诚信(FTSafe)    ARM 时钟智能狗USB\\VID_096E&PID;_0403 飞天诚信(ftsafe) 飞天6无驱型 加密锁 rockey6 smart R6USB\\VID_83D3&PID;_3773 域天(域之天) 域之天 域天 专业型/经济易用型 加密锁 USB\\VID_3689&PID;_8762 域天(域之天) 域之天 域天 密码型 加密锁 USB\\VID_1199&PID;_8282 域天(域之天) 域之天 域天 简单型 加密锁 USB\\VID_1BC0&PID;_1001 深思洛克(SenseLock) 灵锐 I(Living) 加密狗,无驱型USB\\VID_1BC0&PID;_8101 深思洛克(SenseLock) 灵锐 定制加密狗,无驱型USB\\VID_04B4&PID;_4A58 深思洛克(SenseLock) 深思 3(sense3)加密狗,无驱型USB\\VID_04B4&PID;_4A59 深思洛克(SenseLock) 深思 3(sense3)加密狗,有驱型USB\\VID_1BC0&PID;_8013 深思洛克(SenseLock) 精锐 E(Elite-E)智能狗,无驱型USB\\VID_0471&PID;_485D 深思洛克(senseLock) SenseIV2.x 深思洛克 sense4 senseIV 深思4 有驱USB\\VID_0471&PID;_485E 深思洛克(senseLock) SenseIV2.x 深思洛克 sense4 senseIV 深思4 无驱USB\\VID_1312&PID;_2012 域天(域之天)域之天 域天 32位智能型 易用型智能锁 加密锁 无驱USB\\VID_1312&PID;_1912 域天(域之天)域之天 域天 32位智能型(有驱型)USB\\   VID_1312&PID;_2012 域天(域之天)域天(域之天)简单智能型USB\\VID_3689&PID;_3689 EncryptPE 订制型(域天)EPE OEM加密狗 域天密码型 EncryptPE订制型 USB\\VID_5042&PID;_FFFF 安全芯 schip 安全芯UKF-002USB\\VID_08E2&PID;_0002 赛孚耐(SafeNet) safenet microdog UMI 彩虹加密狗 微狗USB\\VID_08E2&PID;_0004 赛孚耐(SafeNet) safenet softdog UDA 彩虹加密狗 软件狗USB\\VID_08E2&PID;_0005 赛孚耐(SafeNet) 精灵狗UGA(GeniusDog),有驱型USB\\VID_08E2&PID;_0006 赛孚耐(SafeNet) safenet GrandDog 宏狗UGRAUSB\\VID_08E2&PID;_0008 赛孚耐(SafeNet) safenet SuperDog 超级狗USB\\VID_04B9&PID;_0300.DeviceDesc="SafeNet USB SuperPro/UltraPro" USB\\VID_04B9&PID;_0301.DeviceDesc="SafeNet USB Security Security Token" USB\\VID_04B9&PID;_0302.DeviceDesc="SafeNet USB Security Security Token" USB\\VID_04B9&PID;_0303.DeviceDesc="SafeNet USB Security Security Token&   quot; USB\\\\VID_04B9&PID;_0304.DeviceDesc="SafeNet USB Security Security Token" USB\\VID_04B9&PID;_8000.DeviceDesc="SafeNet Sentinel Hardware Key" USB\\VID_04B9&PID;_8001.DeviceDesc="SafeNet Sentinel Hardware Key RTC" USB\\VID_04B9&PID;_8002.DeviceDesc="SafeNet Sentinel Hardware Key Mega-Memory" USB\\VID_04B9&PID;_8003.DeviceDesc="SafeNet Sentinel Hardware Key Mega-Memory RTC" USB\\VID_04B9&PID;_8004.DeviceDesc="SafeNet Sentinel Dual Hardware Key" USB\\VID_04B9&PID;_8005.DeviceDesc="SafeNet Sentinel Dual Hardware Key RTC"USB\\VID_0925&PID;_A508 北京磐石诚信NT系列加密狗USB\\VID_7F5E&PID;_DE5D 广州飞盾NT系列加密锁USB\\VID_5042&PID;_???? 江波龙(NetCom) 安全芯(SChip) 加密狗,有驱型USB\\VID_5149&PID;_???? 江波龙(NetCom) 易锁(SimpleKey)加密狗,无驱型   USB\\VID_0925&PID;_7816 世纪龙脉(Century Longmai) NOX 时钟狗,无驱型USB\\VID_0925&PID;_9627 世纪龙脉(Century Longmai) NOX+ 单机狗,无驱型USB\\VID_0925&PID;_7A13 世纪龙脉(Century Longmai) DAM2+网络狗,无驱型USB\\VID_0925&PID;_5906 世纪龙脉(Century Longmai) NOX 定制狗,无驱型USB\\VID_0925&PID;_6B05 世纪龙脉(Century Longmai) NOX 加密狗,无驱型USB\\VID_0925&PID;_7A21 世纪龙脉(Century Longmai) NOX2 加密狗,无驱型USB\\VID_0925&PID;_7122 世纪龙脉(Century Longmai) DAM2+加密狗,无驱型USB\\VID_0925&PID;_5624 世纪龙脉(Century Longmai) DAM2 加密狗,无驱型USB\\VID_0925&PID;_8705 世纪龙脉(Century Longmai) NOX5 加密狗 智能狗,无驱型USB\\VID_0925&PID;_7504 世纪龙脉(Century Longmai) NOX5 主锁USB\\VID_0529&PID;_0001 阿拉丁(Aladdin) HASP HL Time 有驱型USB\\VID_0529&PID;_0001 阿拉丁(Aladdin) HandLock 有驱型USB\\VID_0830&PID;_2002 和升达 SK-USB180 无驱型USB\\VID_5149&PID;_EACE 杭州唯赛 易锁(Simple Key) 无驱型USB\\VID_   6A75&PID;_9801 上海十条电子 JSP-C USB Key 有驱型USB\\VID_10F7&PID;_8469 MegaLock 无驱型USB\\VID_064F&PID;_0BD8 WIBU WIBU RU+加密狗,有驱型

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值