PAT 2020年秋 7-1 Panda and PP Milk (20 分) AC代码

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 (≤104) 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

思路:将所有点奶量初始化为200,然后所有点用两个函数来走,一个向左,一个向右

trail函数:如果不严格有向,按照要求假想增加,如果当前值比假想值小,更新当前值

AC代码:

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n,sum=0;
struct node{
	int weight;
	int milk=200;
}Node[10000];
void trailleft(int index){
	if(index-1<0) return;
	if(Node[index-1].weight>Node[index].weight){
		if(Node[index-1].milk<Node[index].milk+100){
			Node[index-1].milk=Node[index].milk+100;
		}
	}else if(Node[index-1].weight==Node[index].weight){
		if(Node[index-1].milk<Node[index].milk){
			Node[index-1].milk=Node[index].milk;
		}
	}else{
		return;
	}
	trailleft(index-1);
}
void trailright(int index){
	if(index+1>n) return;
	if(Node[index+1].weight>Node[index].weight){
		if(Node[index+1].milk<Node[index].milk+100){
			Node[index+1].milk=Node[index].milk+100;
		}
	}else if(Node[index+1].weight==Node[index].weight){
		if(Node[index+1].milk<Node[index].milk){
			Node[index+1].milk=Node[index].milk;
		}
	}else{
		return;
	}
	trailleft(index+1);
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		scanf("%d",&Node[i].weight);
	}
	for(int i=0;i<n;i++){
		trailleft(i);
		trailright(i);
	}
	for(int i=0;i<n;i++){
		sum+=Node[i].milk;
	}
	printf("%d\n",sum);
	return 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+加密狗,有驱型
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值