日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

uva 11054——Wine trading in Gergovia

發(fā)布時(shí)間:2023/11/30 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 uva 11054——Wine trading in Gergovia 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題意:有n個(gè)村莊,每個(gè)村莊要么買酒(+),要么賣酒(-),要求供需平衡,求最小代價(jià)(代價(jià)k為把k個(gè)單位的酒運(yùn)到相鄰的村莊)。


思路:貪心。可以把第1個(gè)村莊的所有酒都從第2個(gè)村莊運(yùn)來,那么12可以合二為一,其他村莊需要運(yùn)a+b的酒到12村莊,依次類推。


code:

#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <cstring> #include <sstream> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <map> #include <set> #include <bitset>using namespace std;typedef long long ll; typedef unsigned long long ull; typedef long double ld;const int INF=0x3fffffff; const int inf=-INF; const int N=1000000; const int M=2005; const int mod=1000000007; const double pi=acos(-1.0);#define cls(x,c) memset(x,c,sizeof(x)) #define cpy(x,a) memcpy(x,a,sizeof(a)) #define fr(i,s,n) for (int i=s;i<=n;i++) #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define lrt rt<<1 #define rrt rt<<1|1 #define middle int m=(r+l)>>1 #define lowbit(x) (x&-x) #define pii pair<int,int> #define mk make_pair #define IN freopen("in.txt","r",stdin); #define OUT freopen("out.txt","w",stdout);int main() {int n;while (~scanf("%d",&n),n){ll ans=0,a,la=0;fr(i,1,n){cin>>a;ans+=abs(la);la+=a;}printf("%lld\n",ans);} }

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)

總結(jié)

以上是生活随笔為你收集整理的uva 11054——Wine trading in Gergovia的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。