uva 11054——Wine trading in Gergovia
生活随笔
收集整理的這篇文章主要介紹了
uva 11054——Wine trading in Gergovia
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
題意:有n個村莊,每個村莊要么買酒(+),要么賣酒(-),要求供需平衡,求最小代價(代價k為把k個單位的酒運到相鄰的村莊)。
思路:貪心。可以把第1個村莊的所有酒都從第2個村莊運來,那么12可以合二為一,其他村莊需要運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)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎
總結
以上是生活随笔為你收集整理的uva 11054——Wine trading in Gergovia的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 非亲姐妹剧情介绍
- 下一篇: 成都大熊猫繁育研究基地几点去合适