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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Protecting the Flowers(POJ-3262)

發布時間:2025/3/17 编程问答 14 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Protecting the Flowers(POJ-3262) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Problem Description

Farmer John went to cut some wood and left N (2 ≤ N ≤ 100,000) cows eating the grass, as usual. When he returned, he found to his horror that the cluster of cows was in his garden eating his beautiful flowers. Wanting to minimize the subsequent damage, FJ decided to take immediate action and transport each cow back to its own barn.

Each cow i is at a location that is Ti minutes (1 ≤ Ti ≤ 2,000,000) away from its own barn. Furthermore, while waiting for transport, she destroys Di (1 ≤ Di ≤ 100) flowers per minute. No matter how hard he tries, FJ can only transport one cow at a time back to her barn. Moving cow i to its barn requires 2 × Ti minutes (Ti to get there and Ti to return). FJ starts at the flower patch, transports the cow to its barn, and then walks back to the flowers, taking no extra time to get to the next cow that needs transport.
Write a program to determine the order in which FJ should pick up the cows so that the total number of flowers destroyed is minimized.

Input

Line 1: A single integer N?
Lines 2..N+1: Each line contains two space-separated integers, Ti and Di, that describe a single cow's characteristics

Output

Line 1: A single integer that is the minimum number of destroyed flowers

Sample Input

6

3 1
2 5
2 3
3 2
4 1
1 6

Sample Output

86

題意:將n頭牛趕回牛圈,每頭牛在被趕之前每秒破壞Di朵花,趕?;厝ヒ═i×2的時間,在趕牛的過程中,牛不能破壞花,求趕完所有牛后,被破壞花的最小值。

思路:

典型貪心算法,先對牛的破壞度進行排序,然后順序趕牛計算破壞度即可。

設兩頭牛 A、B,要先趕走破壞大的,留下破壞小的牛。若先趕走 A,則 B 造成 2×TA×DB 的損失;若先趕走B,則 A 造成 2×TA×DB 的損失,因此判斷?TA×DB 與 TA×DB 即可。

推廣到 n 頭牛,則排序標準為:Ti×Dj > Tj×Di

Source Program

#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<string> #include<cstdlib> #include<queue> #include<vector> #define INF 0x3f3f3f3f #define PI acos(-1.0) #define N 100100 #define MOD 123 #define E 1e-6 using namespace std; struct Node {long long x;long long y; }a[N];int cmp(Node a,Node b) {return b.x*a.y>a.x*b.y; }int main() {int n;while(scanf("%d",&n)!=EOF){memset(a,0,sizeof(a));long long sum=0;for(int i=0;i<n;i++){scanf("%lld%lld",&a[i].x,&a[i].y);sum+=a[i].y;//計算所有牛在花園中每秒的破壞度}sort(a,a+n,cmp);//對牛按破壞度排序long long num=0;for(int i=0;i<n-1;i++){sum-=a[i].y;//趕走一頭牛后,減去該牛在花園中每秒的破壞度num+=2*sum*(a[i].x);//計算當前總破壞度}printf("%lld\n",num);}return 0; }

?

總結

以上是生活随笔為你收集整理的Protecting the Flowers(POJ-3262)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 欧美日韩国产一区二区三区 | 亚洲自拍偷拍精品 | 亚洲精品在线免费观看视频 | 亚洲人成在线免费观看 | 亚洲精品国产suv一区 | 中文字幕乱码中文乱码b站 国产一区二区三区在线观看视频 | 黑人vs亚洲人在线播放 | 国产亚洲AV无码成人网站在线 | 国产91大片 | 亚洲欧美自拍偷拍 | youjizz亚洲女人 | 香蕉视频一区二区 | 自拍亚洲欧美 | 免费裸体美女网站 | 男生看的污网站 | 天天综合网久久综合网 | 亚洲一区无 | 羞羞草影院 | 成人看 | 男人操女人网站 | 日韩av一区二区在线观看 | 韩日免费视频 | 亚洲国产精品一区二区久久hs | 久久国产视频精品 | 国产精品久久久久久久久晋中 | jizz亚洲女人高潮大叫 | 国产精品久久久久久一区二区三区 | 91性高潮久久久久久久久 | 久久久国产成人一区二区三区 | 精品久久免费视频 | 日本免费网址 | 日美一级片 | 亚洲精品免费观看 | 久久性感美女视频 | 日本精品免费一区二区三区 | 狠狠操影视 | 国产伦精品一区二区三区精品 | 国产精品久久久久久久久毛片 | 白白色视频在线 | 青青av| 影音先锋国产精品 | 96看片| 国模无码视频一区二区三区 | 国产一级二级 | 国产网红女主播精品视频 | 精品免费视频一区二区 | 国产片淫乱18一级毛片动态图 | 天天看天天摸天天操 | 99免费在线| 亚洲不卡视频在线观看 | 高清一区二区三区四区五区 | 人人草网站 | 久久尤物 | 麻豆资源 | 亚洲ⅴ国产v天堂a无码二区 | 欧美日韩a级 | 欧美久久久久久久久久久 | 公车激情云雨小说 | 秋霞视频一区二区 | 天堂资源地址在线 | 丰满人妻一区二区三区免费 | 欧美一级二级视频 | 无码不卡av东京热毛片 | 亚洲aa| 青青艹在线视频 | 日本久久中文字幕 | 亚洲激情| 小早川怜子一区二区三区 | 免费观看全黄做爰的视频 | 五月激情婷婷网 | 精品丰满少妇一区二区三区 | videos亚洲| 阿v视频免费在线观看 | 青青草视频播放 | 欧美天天 | 99精品视频一区二区三区 | 美女国产一区 | 少妇无码一区二区三区 | 午夜精品久久久久久久第一页按摩 | 五级 黄 色 片 | 欧美日韩在线精品 | 日韩一级黄色大片 | 啪啪.com| 国产二级毛片 | 中文字幕33页| 欧美brazzers | 高潮毛片无遮挡高清免费 | 成人一级片在线观看 | 久久美女视频 | 毛片基地免费观看 | 操欧美女| 夜夜嗨av禁果av粉嫩av懂色av | 亚洲人成免费电影 | 五月婷在线 | 中国久久| 少妇xxxx| 欧美性猛交 xxxx | 韩国伦理在线看 | 综合色天天 |