A-removing Columns
Greedy.
can only be vertical non-diminishing as far as possible, when a row appears in the dictionary is larger than the previous line of the case, you do not have to consider this line.
The code is as follows:
#include <iostream> #include <string.h> #include <math.h> #include <queue> #include < algorithm> #include <stdlib.h> #include <map> #include <stdio.h>using namespace Std;char s[1002][ 1002];int A[1002];int Main () {int n, m, I, J, ans, flag; while (scanf ("%d%d", &n,&m)!=eof) {memset (a,0,sizeof (a)); for (i=0;i<n;i++) {scanf ("%s", S[i]); } ans=0; flag=0; for (i=0;i<m;i++) {for (j=1;j<n;j++) {if (!flag&&s[j][i]& Lt;s[j-1][i]) {flag=1; ans++; Break } else if (Flag&&!a[j]&&s[j][i]<s[j-1][i]) { flag=1; ans++; Break }} if (J>=n) {flag = 1; for (j=1;j<n;j++) {if (S[j][i]>s[j-1][i]) { A[j]=1; }}}} printf ("%d\n", ans); } return 0;}
B-tennis Game
Two points.
Enumerate T, then keep looking for the next node and determine if it is feasible. The time complexity is N*log (n) *log (n).
The code is as follows:
#include <iostream> #include <string.h> #include <math.h> #include <queue> #include < algorithm> #include <stdlib.h> #include <map> #include <stdio.h>using namespace Std;int s[110000], DP1[110000], dp2[110000], c1[110000], c2[110000];int bin_search (int x, int y, int n) {int low=1, high=n, Mid, ans=n +1; while (Low<=high) {mid=low+high>>1; if (dp1[mid]>=x| | dp2[mid]>=y) {high=mid-1; Ans=mid; } else low=mid+1; } return ans; struct Node {int s, t;} Fei[100000];int CMP (node f1, node F2) {if (F1.S==F2.S) return f1.t<f2.t; return F1.S<F2.S;} int main () {int n, a, B, I, C, ans1, Ans2, Sum1, sum2, K, flag, CNT, TMP; while (scanf ("%d", &n)!=eof) {cnt=0; dp1[0]=dp2[0]=0; for (I=1; i<=n; i++) {scanf ("%d", &s[i]); if (s[i]==1) {dp1[i]=dp1[i-1]+1; DP2[I]=DP2[I-1]; } else {dp1[i]=dp1[i-1]; dp2[i]=dp2[i-1]+1; }} for (i=n; i>=1; i--) {sum1=sum2=0; flag=ans1=ans2=0; k=0; Tmp=0; while (k<n) {k=bin_search (sum1+i,sum2+i,n); if (k==n+1) continue; if (dp1[k]==sum1+i) {ans1++; Tmp=1; } else {ans2++; tmp=2; } Sum1=dp1[k]; SUM2=DP2[K]; } if (K==N&&ANS1!=ANS2) {if (ans1>ans2&&tmp==2) | | | (ans1<ans2&&tmp==1)) Continue; fei[cnt].t=i; Fei[cnt++].s=max (ANS1,ANS2); }} printf ("%d\n", CNT); Sort (fei,fei+cnt,cmp); for (i=0; i<cnt; i++) {printf ("%d%d\n", fei[i].s,fei[i].t); }} return 0;}
C-distributing Parts
stl+ greedy.
Not with set AH. It becomes so easy to use the set. Drunk.
The first dimension, the two-dimensional into a one-dimensional, then first by the right endpoint value or the left end of the value of the order. That's all that's left to find the other end of the point, with two points on it.
The code is as follows:
#include <iostream> #include <string.h> #include <math.h> #include <queue> #include < algorithm> #include <stdlib.h> #include <map> #include <set> #include <stdio.h>using namespace std; #define LL __int64int d[110000];struct Node {int L, r, K, id;} a[110000], B[110000];int CMP (node F1, Node F2) {if (F1.R==F2.R) return f1.l<f2.l; return F1.R<F2.R;} struct point {int x, ID; Point () {} point (int x, int id): x (x), ID (ID) {} BOOL operator < (const point& a) const { if (x==a.x) return id<a.id; Return x<a.x; }};int Main () {int n, I, J, K, M, CNT; scanf ("%d", &n); for (i=0; i<n; i++) {scanf ("%d%d", &A[I].L,&A[I].R); A[i].id=i; } scanf ("%d", &m); for (i=0; i<m; i++) {scanf ("%d%d%d", &B[I].L,&B[I].R,&B[I].K); B[i].id=i; } set<point>q; Q.clear (); Set<point>::iterator it; Sort (a,a+n,cmp); Sort (b,b+m,cmp); j=0; cnt=0; for (i=0; i<m; i++) {when (J<N&&A[J].R<=B[I].R) {Q.insert (Point (a[ J].l,a[j].id)); j + +; } for (k=0, k<b[i].k; k++) {it=q.lower_bound (point (b[i].l,-1)); if (It==q.end ()) {break; } point Tmp=*it; D[tmp.id]=b[i].id; Q.erase (TMP); cnt++; }} if (Cnt<n) puts ("NO"); else {puts ("YES"); for (i=0; i<n; i++) {printf ("%d", d[i]+1); }} return 0;}
Codeforces Round #283 (Div. 1) Problem solving report A.B.C.