8.2/baltic God (water) problem

Source: Internet
Author: User

bzoj1334:

The Descriptionn political party will form a joint cabinet, each party has its own number of seats. Now I want you to find a way to choose a party that has more seats than half of the total, and the more seats the Union cabinet has, the better. For a joint cabinet, if a party withdraws, the other party is still more than half the total number of seats, the party is called superfluous, which is not allowed. The first line of input gives how many political parties there are. The value is less than or equal to 300 the number of seats for each party is given below. Total number of seats is less than or equal to 100000Output the maximum number of seats in your cabinet plan. Backpack DP. At first thinking of greedy greedy ... Later, under the guidance of Yyl to think of DP. Found half still can't do it. Finally, under the guidance of Yyl embarked on the path ... Moved...
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace STD; #define REP (I,s,t) for (int. i=s;i<=t;i++) #define DWN (i,s,t) for (int i=s;i>=t;i--) #define CLR (x,c) memset (X,c, sizeof (x)) int read () {int X=0;char C=getchar (), while (!isdigit (c)) C=getchar (), while (IsDigit (c)) x=x*10+c-' 0 ', c= GetChar (); return x;} int F[100005];int A[100005];int Main () {int n=read (), Sum=0,ans=-1;rep (i,1,n) A[i]=read (), Sum+=a[i];sort (a+1,a+n+1); f [0]=1;dwn (i,n,1) dwn (J,sum/2+a[i],a[i]) if (F[j-a[i]]) F[j]=1,ans=max (ans,j);p rintf ("%d\n", ans); return 0;}

bzoj1339:

Description Bandits prepare to transfer drugs from one station to another station, the police are ready to carry out the have been supervised. There is a price to be have been supervised for each station, and now the police want to use the minimum cost to control some stations, so that after the removal of these stations, the bandits can not reach the target point from the original initial point of input n,m represents the total number of stations, and how many two-way side to connect them. 2<=n<=200, 1 <=m<=20000. The second line gives two numbers, a, a, a, and a target point for the culprit. 1<=a,b<=n,a<>b. Then there are N rows, giving the money needed to have been supervised the first station, not more than 10 000 000 down the M line, to describe the structure of the diagram. How much money does the output need at least? Hmm bare minimum cut-off point.
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace STD; #define REP (I,s,t) for (int. i=s;i<=t;i++) #define CLR (x,c) memset (x,c,sizeof (x)) #define QWQ (x) for (Edge *o=head[x ];o;o=o->next) int read () {int X=0;char C=getchar (), while (!isdigit (c)) C=getchar (), while (IsDigit (c)) x=x*10+c-' 0 ', C=getchar (); return x;} const int NMAX=405;CONST int Maxn=1e5+5;const int inf=0x7f7f7f7f;struct edge{int to,cap;edge *next,*rev;}; Edge Edges[maxn],*pt=edges,*head[nmax],*cur[nmax],*p[nmax];int cnt[nmax],h[nmax];void Add (int u,int v,int D) {pt-> to=v;pt->cap=d;pt->next=head[u];head[u]=pt++;} void Adde (int u,int v,int d) {Add (u,v,d); add (v,u,0); head[u]->rev=head[v];head[v]->rev=head[u];} int maxflow (int s,int t,int n) {clr (cnt,0); cnt[0]=n;clr (h,0); int Flow=0,a=inf,x=s;edge *e;while (h[s]<n) {for (e=cur[ X];e;e=e->next) if (E->cap>0&&h[e->to]+1==h[x]) break;if (e) {p[e->to]=cur[x]=e;a=min (a,e- &GT;CAP) x=e->to;if (x==t) {while(X!=s) P[x]->cap-=a,p[x]->rev->cap+=a,x=p[x]->rev->to;flow+=a,a=inf;}} Else{if (!--cnt[h[x]]) break;h[x]=n;for (e=head[x];e;e=e->next) if (e->cap>0&&h[x]>h[e->to]+ 1) cur[x]=e,h[x]=h[e->to]+1;cnt[h[x]]++;if (x!=s) x=p[x]->rev->to;}} return flow;} int main () {int n=read (), M=read (), S=read (), T=read (), T+=n;rep (i,1,n) Adde (I,i+n,read ()), Rep (i,1,m) {int u=read (), v= Read (); Adde (U+n,v,inf); Adde (V+n,u,inf);} printf ("%d\n", Maxflow (S,t,n+n)); return 0;}

bzoj1342:

Description Mute problem in digital recording, the sound is described by a sequence of numbers that represent air pressure, each of which is called a sample, and the interval between each sample is a certain amount of time. Many sound processing tasks require that the recorded sound be divided into a few non-silent segments separated by silence. To avoid dividing into too many or too few non-silent segments, muting is usually defined as: M-sampled sequences, where the difference between the maximum and minimum values sampled in the sequence does not exceed a specific threshold of C. Please write a program to detect the Silence in N samples. The first line of input has three integers n,m,c (1<= n<=1000000,1<=m<=10000, 0<=c<=10000), respectively, representing the total number of samples, the length of the mute, and the maximum allowable noise level in silence. The 2nd row n integer ai (0 <= ai <= 1,000,000) represents each sampled value of the sound, separated by a space between every two integers. Output lists all mute start positions I (I meet Max (A[i, ..., i+m−1]) −min (a[i, ..., i+m−1]) <= c), each line represents the starting position of a mute, in the order in which it appears. If there is no mute, the output is none. I think it seems to be O (n) practice, to maintain the maximum minimum number of times small should be able, but very troublesome ... And then found to use the monotonous queue maintenance can be ...
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace STD; #define REP (I,s,t) for (int. i=s;i<=t;i++) #define DWN (i,s,t) for (int i=s;i>=t;i--) #define CLR (x,c) memset (X,c, sizeof (x)) int read () {int X=0;char C=getchar (), while (!isdigit (c)) C=getchar (), while (IsDigit (c)) x=x*10+c-' 0 ', c= GetChar (); return x;} char num[7];void print (int x) {int len=0;while (x) {num[++len]=x%10+ ' 0 '; x/=10;} Dwn (i,len,1) Putchar (Num[i]);p utchar (' \ n ');} const int Nmax=1000005;int a[nmax],q[nmax],q[nmax];int Main () {int n=read (), M=read (), C=read (); Rep (I,1,n) A[i]=read (); int S=1,t=1,l=1,r=1;q[1]=1,q[1]=1;bool Flag=false;rep (i,2,n) {while (s<=t&&q[s]+m<=i) S++;while (s< =t&&a[q[t]]<=a[i]) t--;q[++t]=i;while (l<=r&&q[l]+m<=i) l++;while (l<=r&&a[Q[r ]]>=a[i]) r--; Q[++r]=i;if (a[q[s]]-a[q[l]]<=c&&i>=m) flag=true,print (i-m+1);//printf ("%d:%d%d\n", I,q[s],Q[l]);} if (!flag) printf ("none\n"); return 0;}

bzoj1349:

Descriptionwrite a program to calculate integer square roots. Inputthe input is the read from a text file named Squint.in. Its is line consists of an integer 0 < = N < 2^63. Outputits consists of the smallest nonnegative integer q such that q^2 >= N. Qaq ...
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include < cmath>using namespace std; #define REP (i,s,t) for (int i=s;i<=t;i++) #define LL Long Longint main () {ll a;scanf ("%lld" , &a); ll tmp= (LL) sqrt (a); if (tmp*tmp==a) {printf ("%lld\n", TMP);} else printf ("%lld\n", tmp+1); return 0;}

bzoj1355:

Description gives you a string that is formed by the constant self-connection of a string. But this string is indeterminate, and now just want to know what the shortest length is. The first line of input gives the length of the string, 1 < l≤1,000,000. The second line gives a string that consists entirely of lowercase letters. Output outputs the shortest length I want to die with AC automaton water past. But the space blew up ... But let's put the AC automaton on ...
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include < queue>using namespace std; #define REP (i,s,t) for (int i=s;i<=t;i++) const int Nmax=1000006;char s[nmax];int Ch[nmax ][26],fail[nmax],f[nmax],pt=0;void Insert () {int Len=strlen (s), T=0;rep (i,0,len-1) {if (!ch[t][s[i]-' a ']) ch[t][s[i]- ' A ']=++pt;t=ch[t][s[i]-' a ']; f[t]=i+1;}} Queue<int>q;int n;void Getfail () {q.push (0); Fail[0]=0;while (!q.empty ()) {int X=q.front (); Q.pop (); Rep (i,0,25) { if (Ch[x][i]) Q.push (Ch[x][i]), Fail[ch[x][i]]=x==0?0:ch[fail[x]][i];else ch[x][i]=x==0?0:ch[fail[x]][i];}} printf ("%d\n", N-f[fail[n]]);} int Mian () {scanf ("%d", &n), scanf ("%s", s), insert (); Getfail (); return 0;}

bzoj1369:

Description gives a tree, requires you to mark the tree node on the weight, the weight can be any positive integer only limit condition is the two nodes in the adjacent can not be labeled the same weight, requires a scheme, so that the total value of the whole tree is minimal. Input first gives a number n, which means that there are n points on the tree, n<=10000 below the N-1 line, representing two points connected to the output of the minimum total weight of the first thought is 1 and 2 is OK, hand it up to WA. Then think of the counter example. Tree-shaped DP. Make sure you want to be careful ...
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace STD; #define REP (I,s,t) for (int. i=s;i<=t;i++) #define DWN (i,s,t) for (int i=s;i>=t;i--) #define CLR (x,c) memset (X,c, sizeof (x)) #define QWQ (x) for (edge *o=head[x];o;o=o->next) int read () {int X=0;char C=getchar (), while (!isdigit (c)) c= GetChar (); while (IsDigit (c)) x=x*10+c-' 0 ', C=getchar (); return x;} const int Nmax=10005;const int inf=0x7f7f7f7f;struct edge{int to;edge *next;}; Edge Edges[nmax<<1],*pt=edges,*head[nmax];int dp[nmax][4];void Add (int u,int v) {pt->to=v;pt->next=head[ u];head[u]=pt++;p t->to=u;pt->next=head[v];head[v]=pt++;} void Dfs (int x,int fa) {QWQ (x) if (O-&GT;TO!=FA) {DFS (O-&GT;TO,X); Rep (i,1,3) {int Ans=inf;rep (j,1,3) if (i!=j) ans=min (ans , Dp[o->to][j]);DP [X][i]+=ans;}} Rep (i,1,3) dp[x][i]+=i;} int main () {int n=read (); Rep (i,1,n-1) {int u=read (), V=read (); Add (u,v);} DFS (1,0); int Ans=inf;rep (i,1,3) ans=min (Ans,dp[1][i]);p rintf ("%d\n", ans); return 0;}

bzoj1370:

Description in a city live n person, any two people know not friends is the enemy, and satisfaction: 1, my friend's friend is my friend, 2, my enemy's enemy is my friend; all the people who are friends form a gang. Tell you about this n person's m piece of information, that is, some two people are friends, or some two people are enemies, ask you to write a program to calculate how many of the city may have a number of groups? Input 1th behavior N and m,n less than 1000,m less than 5000, the following M-line, each behavior p x y,p value is 0 or 1,p is 0 o'clock, indicating that X and Y are friends, p is 1 o'clock, that x and Y are enemies. Output An integer that indicates that n individuals may have a maximum of several gangs. and check the set. Split each person into two points. However ab friend ac friend BC enemy I do not know how to deal with. Turned the puzzle is actually directly like this can be over?
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace STD; #define REP (I,s,t) for (int. i=s;i<=t;i++) #define DWN (i,s,t) for (int i=s;i>=t;i--) #define CLR (x,c) memset (X,c, sizeof (x)) int read () {int X=0;char C=getchar (), while (!isdigit (c)) C=getchar (), while (IsDigit (c)) x=x*10+c-' 0 ', c= GetChar (); return x;} const int Nmax=2005;int Fa[nmax];char s[5];int Find (int x) {return fa[x]==x?x:fa[x]=find (fa[x]);} int main () {int n=read (), M=read (), U,v;rep (i,1,n+n) fa[i]=i;rep (i,1,m) {scanf ("%s", s), U=read (), V=read (); if (s[0]== ' F ' ) fa[find (U)]=find (v), else Fa[find (u+n)]=find (v), Fa[find (v+n)]=find (u);} Rep (i,1,n) find (i), sort (fa+1,fa+n+1), int ans=1;rep (i,2,n) if (fa[i]!=fa[i-1]) ans++;p rintf ("%d\n", ans); return 0;}

bzoj1375:

The more description, so choosing the best path is a real problem. The roads of the city are two-way, with a fixed travel time for each road and a fee to be paid. The path is made up of contiguous roads. The total time is the sum of the travel time of each road, and the total cost is the summation of the expenses paid by each road. The same origin and destination, if path A is less time-consuming and inexpensive than path B, then we say path A is better than path B. For a path, if no other path is better than it, then the path is called the optimal two-tone path. Such a path may be more than one, or it does not exist at all. This article gives the description information of the Urban transportation network, the starting point and the destination city, and the number of the optimal double-path. The city is not more than 100, the number of sides not more than 300, each side of the cost and time is not more than 100. The first line of input gives the number of points, the number of edges, the start point and the end point. The data below is used to describe how many optimal double-tuning paths are available for this map output%%%CCZ in his patient guidance I finally read the sample ... No, no, you can't delay the time of God Ben ... F[I][J] represents the minimum cost for the I-point distance of J. And then run SPFA just fine. Not at all ... Copies!
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include < queue>using namespace std; #define REP (I,s,t) for (int. i=s;i<=t;i++) #define DWN (i,s,t) for (int i=s;i>=t;i--) # Define CLR (x,c) memset (x,c,sizeof (x)) #define QWQ (x) for (edge *o=head[x];o;o=o->next) int read () {int X=0;char c= GetChar (); while (!isdigit (c)) C=getchar () and while (IsDigit (c)) x=x*10+c-' 0 ', C=getchar (); return x;} const int NMAX=105;CONST int Maxn=605;const int inf=0x7f7f7f7f;struct edge{int to,dist,cost;edge *next;}; Edge Edges[maxn],*pt=edges,*head[nmax];bool inq[nmax][41000];int f[nmax][41000],n;void adde (int u,int v,int D,int w) { pt->to=v;pt->dist=d;pt->cost=w;pt->next=head[u],head[u]=pt++;p T->to=u;pt->dist=d;pt->cost =w;pt->next=head[v],head[v]=pt++;} struct Node{int u,d;node (int u,int D): U (u), D (d) {}};queue<node>q;void SPFA (int s,int t) {clr (f,0x7f); f[s][0]=0; Inq[s][0]=1;q.push (Node (s,0)); while (!q.empty ()) {node X=q.front (); Q.pop (); inq[x.u][x.d]=0;if (x.d>n*nmax-n) continue;qwq (x.u) if (F[x.u][x.d]+o->cost<f[o->to][x.d+o->dist]) {f[o->to][ X.d+o->dist]=f[x.u][x.d]+o->cost;if (!inq[o->to][x.d+o->dist]) {Q.push (node (o->to,x.d+o->dist) ); inq[o->to][x.d+o->dist]=1;}}} int main () {n=read (); int m=read (), S=read (), T=read (), U,v,d,w,dsum=0,csum=0;rep (i,1,m) U=read (), V=read (), D=read (), w= Read (), Adde (u,v,d,w), SPFA (s,t), int ans=0,nmin=inf;rep (i,0,n*nmax-n) {if (F[t][i]==inf) continue;if (f[t][i]>= nmin) continue;nmin=f[t][i];ans++;} printf ("%d\n", ans); return 0;}

bzoj1391:

Description has n jobs, M machines, and you can rent or buy them for every kind of machine. Each work consists of several processes, each of which requires a machine to be completed, and you can do so by purchasing or renting a machine. Now give these parameters, for maximum profit input first row gives n,m (1<=n<=1200,1<=m<=1200) There will be N blocks of data, the first row of each piece of data gives the amount of money to accomplish this task (in [1,5000]) and how many processes The next several lines of two numbers per line, respectively, the completion of the operation of the machine number and the cost of renting it (which in [1,20000]) The last m, each line gives the cost of the purchase of the machine (its [1,20000]) output maximum profit see the question is the minimum cut. Must be the smallest cut ... YY for a long time do not know how to deal with the relationship between rent and buy ... To turn the solution, the "minimum cut guaranteed st is not connected, that is, to ensure that all work assigned a scheme." Then I understand ... Mom, I wouldn't change my mind.
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace STD; #define REP (I,s,t) for (int. i=s;i<=t;i++) #define DWN (i,s,t) for (int i=s;i>=t;i--) #define CLR (x,c) memset (X,c, sizeof (x)) #define QWQ (x) for (edge *o=head[x];o;o=o->next) int read () {int X=0;char C=getchar (), while (!isdigit (c)) c= GetChar (); while (IsDigit (c)) x=x*10+c-' 0 ', C=getchar (); return x;} const int NMAX=4005;CONST int Maxn=3000005;const int inf=0x7f7f7f7f;struct edge{int to,cap;edge *next,*rev;}; Edge Edges[maxn],*pt=edges,*head[nmax],*cur[nmax],*p[nmax];int cnt[nmax],h[nmax];void Add (int u,int v,int D) {pt-> to=v;pt->cap=d;pt->next=head[u];head[u]=pt++;} void Adde (int u,int v,int d) {Add (u,v,d); add (v,u,0); head[u]->rev=head[v];head[v]->rev=head[u];} int maxflow (int s,int t,int n) {clr (cnt,0); CLR (h,0); Cnt[0]=n;int Flow=0,a=inf,x=s;edge *e;while (h[s]<n) {for (e=cur[ X];e;e=e->next) if (e->cap>0&&h[x]==h[e->to]+1) break;if (e) {cur[x]=p[e->to]=e; A=min (A,e->cap); X=e->to;if (x==t) {while (x!=s) p[x]->cap-=a,p[x]->rev->cap+=a,x=p[x]->rev-> To;flow+=a,a=inf;}} Else{if (!--cnt[h[x]]) break;h[x]=n;for (e=head[x];e;e=e->next) if (e->cap>0&&h[x]>h[e->to]+ 1) h[x]=h[e->to]+1,cur[x]=e;cnt[h[x]]++;if (x!=s) x=p[x]->rev->to;}} return flow;} int main () {int n=read (), M=read (), U,v,d,w,s=0,t=n+m+1,ans=0;rep (i,1,n) {u=read (), V=read (), Rep (j,1,v) D=read (), w= Read (), Adde (i,d+n,w); Adde (s,i,u); ans+=u;} Rep (i,1,m) U=read (), Adde (i+n,t,u);p rintf ("%d\n", Ans-maxflow (s,t,t+1)); return 0;}

bzoj1345:

Description for a given sequence A1, ..., an, we do an operation on it. reduce (i), which replaces the elements AI and ai+1 in the sequence with an element, Max (ai,ai+1), to get a new sequence shorter than the original sequence. The cost of this operation is Max (ai,ai+1). After n-1 the operation, you can get a sequence of length 1. Our task is to calculate the lowest cost of the reduce operation step, turning the given sequence into a sequence of length 1. Input first behaves as an integer n (1 <= n <= 1,000,000) representing the length of a given sequence. The next n rows, one integer for each line of AI (0 <=ai<= 1, 000, 000, 000), are the elements in the sequence. Output has only one row, an integer, and the minimum cost of turning the sequence into an element. The greedy of the super God ... Under the guidance of Yyl to the path ... Yyl: Look at this data range is definitely greedy ... I:...
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace STD; #define REP (i,s,t) for (int i=s;i<=t;i++) int read () {int X=0;char C=getchar (), while (!isdigit (c)) C=getchar (); while (IsDigit (c)) x=x*10+c-' 0 ', C=getchar (); return x;} int A[1000005];int Main () {int n=read (); A[1]=read (); Long long Ans=0;rep (i,2,n) A[i]=read (), Ans+=max (A[i],a[i-1]); printf ("%lld\n", ans); return 0;}

Moved ah ... Be with Fly moved ah ...

8.2/baltic God (water) question

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.