洛谷P1204 [USACO1.2]擠牛奶Milking Cows 前綴和

?

這題數據比較水 暴搜都能夠過去

?

 1 #include <cstdio>
 2 #include <cmath>
 3 #include <cstdlib>
 4 #include <algorithm>
 5 #include <string>
 6 #include <iostream>
 7 #include <iomanip>
 8 #include <cstring>
 9 using namespace std ;
10 
11 int n,x,y,mi,ma,now1,now2,ans1,ans2 ;
12 bool f[1000011] ;
13 
14 int main() 
15 {
16     scanf("%d",&n) ;
17     mi = 1000000000 ;  ma = 0 ;
18     for(int i=1;i<=n;i++) 
19     {
20         scanf("%d%d",&x,&y) ;
21         for(int j=x;j<=y;j++) f[ j ] = 1 ;
22         if( x<mi ) mi = x ;
23         if( y>ma ) ma = y ;
24     }
25     for(int i=mi;i<=ma;i++) 
26     {
27         if(f[i]) 
28         {
29             now1++;   now2 = 0 ;
30             if(now1-1>ans1) ans1 = now1-1 ;
31         }
32         else
33         {
34             now1 = 0;  now2++;
35             if(now2+1>ans2) ans2 = now2+1 ;
36         }
37      }
38     printf("%d %d\n",ans1,ans2) ;
39     return 0 ;
40 }

?

?

但其實標算應該是一種前綴和的東西 ?這個前綴和可以用來表示當前時間有幾個人在擠奶

 1 #include <iostream>
 2 using namespace std;
 3 long long zt[1000001];
 4 int main(){
 5     ios::sync_with_stdio(false);
 6     long long now=0,sum=0,beg=1000000,end=0,n,lr,mn=0,mh=0;
 7     bool dy0=false;
 8     cin>>n;
 9     for (int i=0;i<n;++i){
10         cin>>lr;
11         ++zt[lr];
12         beg=min(beg,lr);
13         cin>>lr;
14         end=max(lr,end);
15         --zt[lr];
16     }
17     for (int i=beg;i<=end;++i){
18         now+=zt[i];
19         if (now>0&&!dy0){
20             dy0=true;
21             mn=max(sum,mn);
22             sum=0;
23         }
24         if (now==0&&dy0){
25             dy0=false;
26             mh=max(sum,mh);
27             sum=0;
28         }
29         ++sum;
30     }
31     cout<<mh<<' '<<mn<<endl;
32 }

?

轉載于:https://www.cnblogs.com/third2333/p/6814891.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/541429.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/541429.shtml
英文地址,請注明出處:http://en.pswp.cn/news/541429.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

java script創建對象_JavaScript七種非常經典的創建對象方式

JavaScript創建對象的方式有很多&#xff0c;通過Object構造函數或對象字面量的方式也可以創建單個對象&#xff0c;顯然這兩種方式會產生大量的重復代碼&#xff0c;并不適合量產。接下來介紹七種非常經典的創建對象的方式&#xff0c;他們也各有優缺點。一、工廠模式可以無數…

java 方法 示例_Java掃描儀具有示例的NextNextInt()方法

java 方法 示例掃描器類的hasNextInt()方法 (Scanner Class hasNextInt() method) Syntax: 句法&#xff1a; public boolean hasNextInt();public boolean hasNextInt(int rad);hasNextInt() method is available in java.util package. hasNextInt()方法在java.util包中可用…

axis2開發webservice之編寫Axis2模塊(Module)

axis2中的模塊化開發。能夠讓開發者自由的加入自己所需的模塊。提高開發效率&#xff0c;減少開發的難度。 Axis2能夠通過模塊&#xff08;Module&#xff09;進行擴展。Axis2模塊至少須要有兩個類&#xff0c;這兩個類分別實現了Module和Handler接口。開發和使用一個Axis2模塊…

java 看書瀏覽器官_JAVA讀取文件流,設置瀏覽器下載或直接預覽操作

最近項目需要在瀏覽器中通過url預覽圖片。但發現瀏覽器始終默認下載&#xff0c;而不是預覽。研究了一下&#xff0c;發現了問題&#xff1a;// 設置response的header&#xff0c;注意這句&#xff0c;如果開啟&#xff0c;默認瀏覽器會進行下載操作&#xff0c;如果注釋掉&…

Java PriorityQueue poll()方法與示例

PriorityQueue類poll()方法 (PriorityQueue Class poll() method) poll() method is available in java.util package. poll()方法在java.util包中可用。 poll() method is used to return the first element with removing an element from this PriorityQueue. poll()方法用于…

scrapy抓取淘寶女郎

scrapy抓取淘寶女郎 準備工作 首先在淘寶女郎的首頁這里查看&#xff0c;當然想要爬取更多的話&#xff0c;當然這里要查看翻頁的url,不過這操蛋的地方就是這里的翻頁是使用javascript加載的&#xff0c;這個就有點尷尬了&#xff0c;找了好久沒有找到&#xff0c;這里如果有朋…

map在Java集合_java集合之Map

MapMap用于保存具有映射關系的數據。Map中key不允許重復&#xff0c;value可以重復&#xff0c;key和value之間存在單向一對一關系HashMap和Hashtable區別1 Hashtable線程安全、HashMap線程不安全&#xff0c;所以HashMap性能高一點2 Hashtable不允許用null做key和value&#x…

Java OutputStream close()方法與示例

OutputStream類close()方法 (OutputStream Class close() method) close() method is available in java.io package. close()方法在java.io包中可用。 close() method is used to close this OutputStream stream and free all system resources linked with this stream and …

怎樣在fastboot 里面加入新的命令

fastboot 是android 默認的一種debug 方法。它的優點是在進入linux kernel 之前就可以操作。默認fastboot 支持的命令&#xff1a; usage: fastboot [ <option> ] <command>commands: update <filename> reflash device …

java編寫字符串連接程序注釋_Java 注解自動化處理對應關系實現注釋代碼化

public class EsQuery { private static int DEFAULT_SIZE 100; private final Map termFilter;private final Map rangeFilter;private final Map matchFilter;private int size;private String orderBy null;private String order null; // query 查詢語法, 是否需要 filtere…

getlanguage_Java語言環境getLanguage()方法與示例

getlanguage區域設置類getLanguage()方法 (Locale Class getLanguage() method) getLanguage() method is available in java.util package. getLanguage()方法在java.util包中可用。 getLanguage() method is used to retrieve this Locale language code and the language co…

[轉]Anaconda

安裝 Anaconda Anaconda 可用于 Windows、Mac OS X 和 Linux。可以在 https://www.continuum.io/down... 上找到安裝程序和安裝說明。 如果計算機上已經安裝了 Python&#xff0c;這不會有任何影響。實際上&#xff0c;腳本和程序使用的默認 Python 是 Anaconda 附帶的 Python。…

win10 iot core java_Windows 10 IoT Core 正式版初體驗

今天收到Windows 10 IoT Core Team郵件&#xff0c;Windows 10 IoT Core正式發布。以下記錄了今天在Raspberry Pi 2上的體驗過程&#xff1a;準備工作一臺運行著正版Windows 10且版本不小于10240的個人PCVisual Studio 2015 版本不小于14.0.23107.0 D14Rel Install Visual Stud…

filterwriter_Java FilterWriter flush()方法與示例

filterwriterFilterWriter類flush()方法 (FilterWriter Class flush() method) flush() method is available in java.io package. flush()方法在java.io包中可用。 flush() method is used to flush out the string from this FilterWriter stream. flush()方法用于從此Filter…

VUE2 第五天學習--過渡效果

閱讀目錄 1.理解VUE---過渡效果回到頂部1.理解VUE---過渡效果 1. 過渡的-css-類名會有4個(css) 類名在 enter/leave 在過渡中切換。1. v-enter: 進入過渡的開始狀態。在元素被插入時生效&#xff0c;在下一個幀移除。2. v-enter-active: 進入過渡的結束狀態。在元素被插入時生效…

java 集合addall_Java集合的addAll()方法和示例

java 集合addall集合類的addAll()方法 (Collections Class addAll() method) addAll() Method is available in java.lang package. addAll()方法在java.lang包中可用。 addAll() Method is used to put all the given elements(ele) to the given collection (co). addAll()方…

國家可持續發展議程創新示范區創建工作推進會在北京召開

2019獨角獸企業重金招聘Python工程師標準>>> 為推進地方申報國家可持續發展議程創新示范區相關工作&#xff0c;根據國家可持續發展議程創新示范區創建工作的進展及需求&#xff0c;2017年4月23日—25日&#xff0c;科技部社會發展科技司、中國21世紀議程管理中心在…

java控制臺打印圖片_java——控制臺輸入打印圖形

1. 打印直角三角形需求說明&#xff1a;從控制臺輸入直角三角形的高度(行數)。每行*的數目依次為1、3、5、7等。實現思路&#xff1a;外層循環控制行數&#xff0c;根據用戶輸入的行數得到外層循環條件分析每行打印的內容&#xff1a;每一行均打印*號&#xff0c;第i行的*號數為…

Java日歷compareTo()方法與示例

日歷類的compareTo()方法 (Calendar Class compareTo() method) compareTo() method is available in java.util package. compareTo()方法在java.util包中可用。 compareTo() method is used to compare two Calendar objects or in other words, we can say this method is u…

在struts2中配置自定義攔截器放行多個方法

源碼&#xff1a; 自定義的攔截器類&#xff1a; //自定義攔截器類:LoginInterceptor ; package com.java.action.interceptor; import javax.servlet.http.HttpSession; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionInvocation;im…