当前位置:网站首页>Haut OJ 1221: a tired day
Haut OJ 1221: a tired day
2022-07-05 05:17:00 【hunziHang】
Problem description :
It's early in the morning , Playing outside all day cds, Now I'm tired both physically and mentally , But it is still a whole kilometer away from the gate of the school , So he checked whether there was a bus to take
Walk as little as possible , Sure enough , Although it is very late now , But there are still two buses in operation , So here comes the question ,cds How can I make the shortest way to go ?
Let's assume that the path is set as a straight number axis , There are integer points on the number axis (0,1,2,3,4,……), There is a distance between every two points 1m. It is known that cds On the number axis 0 spot ,
And the school is at 1000 On , The starting and ending points of the two buses are x1, y1, x2, y2, You can't get off halfway , Take a car or not , And ensure that you can wait for the bus ( We assume that cds A lot of time ).
Input :
4 A positive integer x1, y1, x2, y2, Data assurance x1<y1, x2<y2, And all the int Within the scope of ,
Output :
An integer , Occupy a line , Express cds The shortest distance to walk
The sample input :
300 1000 50 301
Sample output :
51
Cause analysis :
1. because for It's from 1 At the beginning , therefore sort The first item should be a+1 Similarly, the last bit a+n+1
2. situation
1. Take a car (2 Kind of ) 2. Take two cars 3. No car
When making two cars, we should discuss the situation at the same time Three situations , The first includes the second , The first and second cars have a crossover , No cross at all
Solution :
#include<bits/stdc++.h>
using namespace std;
#define endl"\n"
typedef struct pos{
int x,y;
}p;
bool cmp(p a,p b)
{
return a.x<b.x;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n1,n2,n3,result,i;
p a[4];
for(i=1;i<=2;i++)
cin>>a[i].x>>a[i].y;
sort(a+1,a+3,cmp);
n1=a[1].x+abs(1000-a[1].y);
n3=a[2].x+abs(1000-a[2].y);
if(a[2].y>a[1].y)
n2=a[1].x+abs(a[1].y-a[2].x)+abs(1000-a[2].y);
else
n2=n1;
result=min(n1,1000);
result=min(result,n2);
cout<<min(result,n3)<<endl;
return 0;
}
边栏推荐
- 2022/7/1学习总结
- 对象的序列化
- [paper notes] multi goal reinforcement learning: challenging robotics environments and request for research
- Page countdown
- National teacher qualification examination in the first half of 2022
- Dotween usage records ----- appendinterval, appendcallback
- [turn to] MySQL operation practice (III): table connection
- Cocos create Jiugongge pictures
- [轉]: OSGI規範 深入淺出
- Simple modal box
猜你喜欢
National teacher qualification examination in the first half of 2022
Research on the value of background repeat of background tiling
Ue4/ue5 illusory engine, material chapter, texture, compression and memory compression and memory
Collapse of adjacent vertical outer margins
[trans]: spécification osgi
对象的序列化
Generate filled text and pictures
[turn to] MySQL operation practice (I): Keywords & functions
嵌入式数据库开发编程(五)——DQL
Stm32cubemx (8): RTC and RTC wake-up interrupt
随机推荐
Grail layout and double wing layout
PR first time
用 Jmeter 工具做个小型压力测试
Solon Auth 认证框架使用演示(更简单的认证框架)
Unity shot tracking object
Ue4/ue5 illusory engine, material chapter, texture, compression and memory compression and memory
Unity get component
[to be continued] I believe that everyone has the right to choose their own way of life - written in front of the art column
Research on the value of background repeat of background tiling
服务熔断 Hystrix
[转]: OSGI规范 深入浅出
Page countdown
Use of snippets in vscode (code template)
一个新的微型ORM开源框架
[allocation problem] 135 Distribute candy
UE4/UE5 虚幻引擎,材质篇(三),不同距离的材质优化
PMP candidates, please check the precautions for PMP examination in July
Time format conversion
Double pointer Foundation
2022/7/1 learning summary