当前位置:网站首页>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;
}
边栏推荐
- Unity writes timetables (without UI)
- Basic knowledge points of dictionary
- [allocation problem] 455 Distribute cookies
- [trans]: spécification osgi
- The difference between heap and stack
- Unity sends messages and blocks indecent words
- Magnifying glass effect
- PMP考试敏捷占比有多少?解疑
- Do a small pressure test with JMeter tool
- UE 虚幻引擎,项目结构
猜你喜欢
2022/7/2 question summary
[to be continued] [UE4 notes] L1 create and configure items
BUUCTF MISC
[interval problem] 435 Non overlapping interval
UE fantasy engine, project structure
UE4/UE5 虚幻引擎,材质篇(三),不同距离的材质优化
Data is stored in the form of table
win10虚拟机集群优化方案
Reverse one-way linked list of interview questions
Heap sort summary
随机推荐
[turn]: OSGi specification in simple terms
Unity connects to the database
质量体系建设之路的分分合合
2022/7/1学习总结
一个新的微型ORM开源框架
[转]:Apache Felix Framework配置属性
Common database statements in unity
Unity writes timetables (without UI)
对象的序列化
Lua GBK and UTF8 turn to each other
[轉]: OSGI規範 深入淺出
Solon Logging 插件的添加器级别控制和日志器的级别控制
[turn to] MySQL operation practice (I): Keywords & functions
PMP考生,请查收7月PMP考试注意事项
Ue4/ue5 illusory engine, material part (III), material optimization at different distances
Lua determines whether the current time is the time of the day
Use of snippets in vscode (code template)
The difference between heap and stack
Unity intelligent NPC production -- pre judgment walking (method 1)
xftp7与xshell7下载(官网)