uva timecard

Read about uva timecard, The latest news, videos, and discussion topics about uva timecard from alibabacloud.com

Uva (10594)

(!Vis[v]) {Vis[v]=true; Q.push (v); } } } } if(d[n]==inf) Break; intA=999999999; for(intu=p[n];u!=-1; u=P[G[U].U]) {a=min (a,g[u].cap-g[u].f); } for(intk=p[n];k!=-1; k=P[G[K].U]) {G[K].F+=A; G[k^1].f-=A; } F+=A; C+=a*D[n]; } if(f==D) coutEndl; Elsecout"impossible.\n";}intMain () { while(SCANF ("%d%d", n,m)! =EOF) {init (); for(intI=1; i) Cin>>E[i].u>>E[i].v>>E[I].W; CIN>>D>>K; Add (0,1D0); for(intI=1; i) {Add (E[I].U,E[I].V,K

UVA 12558 Egyptian fractions (hard version)

,getfirst (b));; ++i){Coutif (b* (maxd+1-d) Breakif (Del.count (i))ContinueV[d]=i;ll B1=b*i;ll A1=a*i-b;ll G=GCD (A1,B1);if (Dfs (A1/G,B1/G,I+1,D+1,MAXD))Ok=true;}return OK;}int main (){scanf ("%d", t);for (int cas=1;cas{Del.clear ();scanf ("%lld%lld%lld", n,m,k);int i,j;ll Del0;while (k--){scanf ("%lld", del0);Del.insert (del0);}int maxd;for (maxd=0;; maxd++){coutmemset (ans,-1,sizeof (ans));if (Dfs (N,m,getfirst (n,m), 0,maxd))Break}printf ("Case%d:%lld/%lld=", cas,n,m);for (I=0;iif (i) printf

UVA 1587 Box (IDEA)

Give the length and width (or width and length) of the 6 rectangles, and ask whether the six rectangles can form a box.The idea is relatively simple, but there are a lot of places to pay attention to.First, because of the length and width of the order, so to deal with (at first only to deal with the later reading of the five groups, no processing of the first group read separately, bad reviews)Then decide if you can divide into 22 identical three groups.If able, enumerate 8 possible equal cases.

UVA 11404 plalidromic subsquence

][b.se]) {a= Pre Dim (a); b =Pre Dim (b); } returnVal Dim (A) Val Dim (b);}//#define LOCALintMain () {#ifdef LOCAL freopen ("In.txt","R", stdin);#endif while(gets (s)) {intLen =strlen (s); for(inti =0; i ) {Rv[len-1-I.] =S[i]; } intHD1,HD2,VL =0; for(inti =1; I ){ intj = len+1-i; DP[I][J]=1; VAL[I][J] = s[i-1]; PRE[I][J] =Nil; if(Dp[i][j] > VL | | (Dp[i][j] = = VL Cmplex (MP (I,J), MP (HD1,HD2)))) {//VL =Dp[i][j]; HD1= i; HD2 =J; } for(intK =1; K 0; forJ

UVA 1418-wonderteam

Test instructions: You n team to play, every two teams to play 2 games, win 3 points, flat 1 points, lose 0 points, after the game to select a Dream team, the number of goals required to score the most, the largest number of wins, the fewest number of missed goals, and three can not be compared with the other column first. Ask about the lowest possible ranking of the Dream team.Analysis: its real 3 limit conditions only the number of victories is most useful, because the dream team can win the

UVA-1343 the Rotation Game (ida*)

The main idea: There are eight digital three-way, to find the minimum number of rotations so that the number of graphs in the middle eight. Rotation rule: For each long row or column, each rotation is to move the data to the position of the head, and the number on the head is placed at the tail. If the number of times is the same, the minimum rotation order of dictionary order is found.Title Analysis: ida*, if currently in the CUR layer, the number of the middle eight number of three-in-one is a

Uva (10986)

Very naked a Dijk algorithm problem, because the vertex number is too many can not be represented by the adjacency matrix, so the critical table is used to representAC Code#include #includestring.h>#include#include#include#includeusing namespacestd;using namespacestd;Const intmaxn=2*50000;#defineINF 99999999structnode{intv; intu; intW; intNext;} V[MAXN];intHEAD[MAXN];intD[MAXN];intn,m,s,t;intTol;intDone[maxn];typedef pairint,int>PII; priority_queueQ;voidinit () {tol=0; memset (Head,-1,sizeof(hea

UVA-12569 Planning mobile Robot on the Tree (Easy Version) (bfs+ State compression)

The main idea: an undirected graph, a robot, a number of stones, each move can only move to the connected node, and only one node can have the same and one thing (robot or stone), to find a robot from the specified position to another specified position of the minimum number of steps, the output move step.Analysis of the problem: the position of the robot and the location of the stone to mark the status of the state, the number of States has a maximum of 15*2^15. Wide search of the.The code is a

UVA 1149 Bin Packing two points + greedy

line.Note:the sample instance and an optimal solution are shown in the? Gure below. Items are numberedFrom 1 to according to the input order.Sample Input1108070153035108020351030Sample Output6Test instructionsGiven the weight of N (nExercisesThe number of our two-pack backpackCheck the time first arrogant to small fill one in each backpackFill it up from big to small, and check if it's done.And just pay attention to the output format.#include #include#include#include#includeusing namespacestd;C

UVA 1614-hell on the

Test instructionsEnter n number, number I ai satisfies 1≤ai≤i. Adds a symbol to each number, and the value is 0.Analysis:Starting with the largest element (assuming K), the SUM/2 can be sorted out. With the removal of the set of K, it will be possible to make up SUM/2-a[k]. As long as sum is even, there must be a solution.Code:  #include #include #include #include using namespace Std;const int maxn=1e6+5;int A[MAXN];int R[MAXN];BOOL CMP (int x,int y){return a[x] }int main (){int n;int i;while (~

UVa 141-the Spot Game

Title: Give you a n*n form, two people take turns to operate, each time in a position to put or win a pawn;If a state, before it appears, then the other wins, ask who wins, if no one wins, output draw.Analysis: DS, data structure, hash function, state compression.Each row is stored in a single bit, a one-dimensional array represents a state, and a hash table is used to store the lookup.Description: Note that the rotated State is considered to be the same.#include

UVA 11992 Fast Matrix Operations (dimensionality reduction)

,inty2) { intRET =0; intSt = x1*c+y1, len = y2-Y1; for(intx = x1; x ) {QL= St; QR = st+Len; RET=Max (ret,querymax1d ()); St+=C; } returnret;}intQuerymin2d (intX1,intY1,intX2,inty2) { intRET =INF; intSt = x1*c+y1, len = y2-Y1; for(intx = x1; x ) {QL= St; QR = st+Len; RET=min (ret,querymin1d ()); St+=C; } returnret;}voidintMain () {//freopen ("In.txt", "R", stdin); intm; while(~SCANF ("%d%d%d",r,c,m)) {QL=0; QR = r*c-1; val =0; SET1D (); while(m--){ intOP, x1,

UVa 548 Tree "recursive traversal of binary trees"

; - StringStream SS (line); -n=0; + intx; - while(ss>>x) a[n++]=x; + returnN>0; A } at - intBuildintL1,intR1,intL2,intR2) { - if(L1GT;R1)return 0; - introot=POST_ORDER[R2]; - intp=L1; - while(in_order[p]!=root) p++; in intCNT=P-L1;//Zuozi Number of nodes -Lch[root]=build (l1,p-1, l2,l2+cnt-1); toRch[root]=build (p+1, r1,l2+cnt,r2-1); + returnRoot; - } the * intbest,best_sum; $ Panax Notoginseng voidDfsintUintsum) { -sum+=u; the if(!lch[u]!Rch[u]) { +

UVA-10003 Cutting Sticks (interval DP)

The main idea: to cut a wooden stick that is long as l at a given n cutting point, the cost per cut is equal to the length of the current stick. The minimum cost to cut into n+1 segments.Topic Analysis: Interval DP. The definition of DP (I,J) represents the cost of the cut interval i~j, then f (i,j) =min (f (i,k) +f (k,j)) +dist (I,J). The complexity of time is N3.The code is as follows:# include  UVA-10003 Cutting Sticks (interval DP)

UVa 12563 Jin Song Rujia second edition example 9-5;

can not confirm the quantity maximum, the time is how much, so to initialize the DP to judge by a special value, namely the complete backpack;In this way, the time of the greatest number of times is guaranteed to be the total time spent;Links: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34887#include#include#include#include#include#include#include#include#includeusingnamespacestd;intdp[10000];constintinf=0x3f3f3f3f;intnext[55];inta[55],t,n;intmain(){intT,cas=1;cin>>T;while(T--){

UVA 1291-dance Dance Revolution (DP)

Title: There are 4 positions, each moving from one position to another requires a specific cost, the minimum cost of a sequence of specified sequences. Only one foot at a time can move, or move and step down.Use D[i][j][u] to indicate that the first I position is complete and the minimum cost in the state (J,u), (J,u) One of which must be equal to A[i], assuming J and A[i] are equal, then either the previous state is (j,u), or the previous state is (k,u), note that the previous state cannot be (

UVa 1346-songs

The main topic: N Records, each with a length and frequency, the problem requires the lowest formula value. For a sort, output the ID of the CD under this sort.Idea: greedy, the longer the length of the back, the lower the frequency to put more behind, so press len/p to sort.#include #include #include #include using namespace Std;struct CD{int id;Double Len;Double p;} cd[100000];int CMP (CD A, CD B){return A.LEN/A.P }int main (){int n,m;while (~SCANF ("%d", n)){for (int i = 0; i scanf ("%d%lf%lf

UVa 11039-building Designing

The main topic: n the absolute value of the different non-0 integers, select as many as possible, into a sequence, so that the positive and negative numbers alternating and absolute value increment.Analysis: Order by absolute size, then scan once, by the way, make a mark.#include #include #include using namespace Std;int cmp (int a,int b){Return ABS (a) }int main (){int cas,a[100000],n;scanf ("%d", cas);for (int ii=1;ii{scanf ("%d", n);for (int i=1;iscanf ("%d", a[i]);Sort (a+1,a+1+n,cmp);int fl

"Basic math Knowledge" UVa 11314-hardly hard

shape, requiring the smallest perimeter, where a, b two point coordinates are given, and the c,d point is required on the x, Y axis positive half axis.Analysis: Symmetric point connection with X, Y axis. Proof very well, the shortest line between two points.1#include 2#include 3#include 4#include 5 #defineError 1e-86 using namespacestd;7 Const intMAXN =10010;8 9 Ten DoubleGet_len (DoubleX1,DoubleY1,DoubleX2,Doubley2) One { A returnsqrt ((y2-y1) * (y2-y1) + (x2-x1) * (x2-x1)); - } - intMain

Uva-10003--cutting Sticks

A very basic interval dp:)#include #include#defineINF 0x3f3f3f3fusing namespacestd;intc[1005];intdp[1005][1005];intMain () {intl, N; while(SCANF ("%d", l)!=eof l) {scanf ("%d", N); for(intI=1; i) {scanf ("%d", C[i]); } c[0]=0; c[++n]=M; for(intstep=2; step) { for(intI=0; i+step) { intj = i+step; DP[I][J]=INF; for(intk=i+1; k) {Dp[i][j]= Min (Dp[i][j], dp[i][k]+dp[k][j]+c[j]-C[i]); }}} printf ("The minimum cutting is%d.\n", dp[0][n]); } return 0;}

Total Pages: 15 1 .... 11 12 13 14 15 Go to: Go

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.