POJ 3225 Help with Intervals 線段樹 成段更新

轉自hh大神的代碼,本來想自己的寫的,可是,各種錯誤,特別是遇到了OLE,只能大面積參考了順便補充一下先代學長的文章#include<cstdio>#include<cstring>#define left l,m,x<<1#define right m+1,r,x<<1|1#define LMT 132090//首先要對集合的各種操作自己手動類比一遍/*********這cov裡面的空分為兩種,一種是真空,一種是用情況的空,真空是0,有情況是-1

ZOJ 2301 Color the Ball 線段樹 區間染色

做法:這題比ural那題簡單,因為是球,所以離散化時記錄區間邊間點和中間的兩個點就好了。//列SUM組的方法也只適用於,空出的的格子可以不用考慮的情況啊#include<cstdio>#include<cstring>#include<algorithm>#define left l,m,x<<1#define right m+1,r,x<<1|1using namespace std;const int

POJ 3277 City Horizon 線段染色

做法:按高度排序之後,直接映射到數組上計算好了。注意LL 用的要及時,WA了許久..#include<cstdio>#include<cstring>#include<algorithm>#define left l,m,x<<1#define right m+1,r,x<<1|1#define LL __int64const int LMT=160003;using namespace std;int

POJ 2777 Count Color 線段樹 成段更新

題意:經過一系列操作之後,求可以看見的顏色數做法:一開始2了用了個數組簡單統計了一下,果斷TLE,所以後來只能想個法子,用節點記錄區間中還有顏色的種類,用位元壓縮即可#include<cstdio>#include<cstring>#define left l,m,x<<1#define right m+1,r,x<<1|1const int LMT=100003;int colo[LMT<<2],ans,L,T;bool

POJ 3264 Balanced Lineup 成段更新

水題一枚...#include<cstdio>#include<cstring>#define left l,m,x<<1#define right m+1,r,x<<1|1#define eps 1e8const int LMT=50002;int hei[LMT<<2],sho[LMT<<2],__hei,__sho;inline int max(int a,int b){return

POJ 1436 Horizontally Visible Segments 線段樹 染色

題意:兩個線段可以相互看見是指兩條線段之間沒有把他們完全遮住的線段。三角形是指,三條線段,兩兩之間可以相互看見。做法:按照橫座標排序,先統計一下在它的範圍內可以看見的顏色,然後在把那些它可以看見的地區染上的它自己的顏色。三角形很少,所以這樣的演算法不會TLE#include<cstdio>#include <iostream>#define LL int//23123 132131const int LMT=40;using namespace std;LL c[LMT]

FZU/FOJ 2105 Problem 2105 Digits Count 成段更新

題意:對一串數字進行抑或某數,和某數,或某數,統計某區間和的操作。做法:對每一位進行統計。看了大神的代碼之後才發現自己犯了個很2 的錯誤#include<cstdio>#include<cstring>#define left l,m,x<<1#define right m+1,r,x<<1|1#define LMT 1000003#define LL intint cov[4][LMT<<2],wei;int

ural 1019 Line Painting 線段樹 區間染色

做法:先統計,後映射到數組上.每一次然a,b-1的地區即可。#include<cstdio>#include<cstring>#include<algorithm>#define left l,m,x<<1#define right m+1,r,x<<1|1const int LMT=35005;const int big=1000000000;using namespace std;int cov[LMT<<2],myx[

ZOJ 2706 Thermal Death of the Universe 線段樹

做法:求平均值是,上取整下取整要考慮正負數啊,然後更新區間時要不要直接除以2了。#include<cstdio>#include<cstring>#define left l,m,x<<1#define right m+1,r,x<<1|1#define LL long longconst int LMT=30003;LL sum[LMT<<2],num[LMT<<2];bool cov[LMT<<2],tag;

ZOJ 3279 Ants

題意:先給定了螞蟻每個等級的成員數量,然後求某隻排名為x的螞蟻的等級。顯然螞蟻的排名按照等級排列,同級的佔有一段連續的地區。做法:瞭解題意後,發現和POJ某題很像#include<cstdio>#include<cstring>#define left l,m,x<<1#define right m+1,r,x<<1|1const int LMT=100003;int have[LMT],cov[LMT<<2];void

POJ 3667 Hotel 線段樹 區間合并

第一道這樣的題目,轉自這裡點擊開啟連結只是照抄了一下,然後體味了一下大神的思維,以及自己的不慎#include<cstdio>#include<iostream>#include<cstring>#define left l,m,x<<1#define right m+1,r,x<<1|1#define LMT 50005using namespace std;//一般都是左子樹多一點int

hdu 1542 Atlantis 面積並 線段樹 掃描線

轉自這裡 #include<cstdio>#include<algorithm>#include<cstring>#define LMT 202#define left l,m,x<<1#define right m+1,r,x<<1|1using namespace std;//shit double int 搞錯了struct line{ double h,l,r; int d; line(void){}

hdu 1754 線段樹 單點更新 水

題意:求一段區間內的最大值,和對原來的數組進行改變做法:入門級的線段樹...#include <iostream>#include <cstdio>#include <cstring>#define LMT 200002#define left l,m,x<<1#define right m+1,r,x<<1|1using namespace std;int smax[LMT<<2];int max(int a,int b)

hdu 1754 Minimum Inversion Number 線段樹 單點更新

題意:輸入一串數字,對其進行一次操作:把潛m個數放到末尾,問最少的pair(i,j)(i<j,a[i]>a[j]),輸入的數字各不相同,且在[0,n-1]內做法:先用線段樹的手法求出原始序列的pair數,然後在移動時,可以發現一個規律,設每當進行某次操作,位於序列中的第m個數為X,此時序列中的pair數為p,有一個操作移動了m-1個數,最終的pair數為p,在形成的序列中x為與序列的頂部,要計算的那個移動m個數的操作可以認為是把X移到該序列的末尾,此時,比x大的數有n-1-x個,比X

POJ 2828 Buy Tickets 線段樹 單點更新

題意:夜裡排隊買車票,每個人都有自己的id號。排隊買票時會插隊,輸入n對數字,每對包括了他想插入的位子,和自己的id號,後插入的人會把先插入的人擠下去做法:把先到的人擠下去真心難類比,那麼就倒過來思考。逆序尋找序列對,後查到的要往後排,這個思想我以後要記住了然後建立樹時,每個節點的值為當前的空餘數,然後就可以類比了,類比的時候要小心...#include<cstdio>#include<cstring>#define left l,m,x<<1#define

POJ 3468 A Simple Problem with Integers 線段樹 成段更新

做法:一開始做的成段更新,有學會了成段更新的一下必要規則#include <iostream>#include <cstdio>#include <cstring>#define left l,m,x<<1#define right m+1,r,x<<1|1#define LL long long#define LMT 100004//成段更新原則:一定要有表現出每一次改變的所有影響//在看題的一開始就要確定使用數值的類型using

hdu 2222 Keywords Search AC自動機 模板

以後就是這個模板了#include <iostream>#include <cstdio>#include <cstring>#include <deque>#define CNUM 26#define LMT 1000005using namespace std;struct node{ node *chl[CNUM]; node *fail; int count; void init() {

POJ 2528 Mayor’s posters 成段更新

做法:抄hh大神的,可是,有些地方自己的小聰明導致了錯誤,記錄一下#include <cstdio>#include <vector>#include <algorithm>#include <cstring>#define left l,m,x<<1#define right m+1,r,x<<1|1#define LMT

POJ 2892 Tunnel Warfare 區間合并線段樹

做法:hdu的較嚴格,加上while即可#include<cstdio>#include<cstring>#include<stack>#define left l,m,x<<1#define right m+1,r,x<<1|1const int LMT=50005;using namespace std;int

POJ 2886 Who Gets the Most Candies? 單點更新

做法:約瑟夫環+類似於POJ 2828的做法#include <cstdio>#include <vector>#include <algorithm>#include <cstring>#define left l,m,x<<1#define right m+1,r,x<<1|1#define LMT 40002//出了map,set,另外的能用數組就用數組//應不應該加點,這個需要考慮,很多情況不需要加點的。using

總頁數: 61357 1 .... 18223 18224 18225 18226 18227 .... 61357 Go to: 前往

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.