BZOJ 1108 [POI2007]天然气管道Gaz
生活随笔
收集整理的這篇文章主要介紹了
BZOJ 1108 [POI2007]天然气管道Gaz
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
題目鏈接
https://www.lydsy.com/JudgeOnline/problem.php?id=1108
思路
看上去好nan的樣子啊。
然而這是道結(jié)論題。
先考慮x軸,如果有這樣的情況:(其中X是天然氣井,O是中轉(zhuǎn)站)
X-----X----O-----O那么怎樣搭配都是最優(yōu)的方案,即 中轉(zhuǎn)站的坐標和減去天然氣井的坐標和。
如果情況是這樣:
X---O------X-----O那么顯然只有一種情況可以選擇,答案就是中轉(zhuǎn)站的坐標和減去天然氣井的坐標和。
最后發(fā)現(xiàn)連數(shù)組都不用開,注意統(tǒng)計答案要用long long。
代碼
#include <cstdio>int n; long long ans;int read() {int x=0,f=1;char ch=getchar();while((ch<'0')||(ch>'9')){if(ch=='-'){f=-f;}ch=getchar();}while((ch>='0')&&(ch<='9')){x=x*10+ch-'0';ch=getchar();}return x*f; }int main() {n=read();for(register int i=1; i<=n; ++i){ans-=read();ans+=read();}for(register int i=1; i<=n; ++i){ans+=read();ans-=read();}printf("%lld\n",ans);return 0; }轉(zhuǎn)載于:https://www.cnblogs.com/Canopus-wym/p/10376199.html
總結(jié)
以上是生活随笔為你收集整理的BZOJ 1108 [POI2007]天然气管道Gaz的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: hadoop(9)--MapReduce
- 下一篇: js/jq基础(日常整理记录)-2-一个