Multi-eighth Field School: Geometry + graph theory + simulation + Find law

Source: Internet
Author: User
Tags bitset cmath

HDU 4946

pid=1002&cid=509 "style=" Color:rgb (26,92,200); Text-decoration:none; Font-family:tahoma; Background-color:rgb (215,235,255) ">area of Mushroom

This problem WA 7 hair before, teammates do, and then debug together for a long time.

It was not sorted at the beginning.

Then the point in the same position is not handled well.

And then take these two questions to a.

#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring > #include <ctime> #include <ctype.h> #include <iostream> #include <map> #include <queue > #include <set> #include <stack> #include <string> #include <vector> #define EPS 1e-10#define INF 0x7fffffff#define maxn 10005#define PI acos ( -1.0) #define seed 31//131,1313typedef Long long ll;typedef unsigned long l    Ong ull;using namespace Std;int x[505],y[505],v[505],vis[505];int cmp (double x) {if (Fabs (x) <eps) return 0;    if (x>0) return 1; return-1;} Inline double Sqr (double x) {return x*x;}    struct point//Point {double x, y;    int POS;    int o;    Point () {} point (double a,double b): X (a), Y (b) {} void input () {scanf ("%lf%lf", &x,&y);    } Friend point operator + (const point &a,const point &b) {return point (A.X+B.X,A.Y+B.Y); } Friend point operator-(const POint &a,const point &b) {return point (A.X-B.X,A.Y-B.Y); } friend bool operator = = (Const point &a,const point &b) {return CMP (a.x-b.x) ==0 &&cmp (a.y-    B.Y) ==0;    } Friend point operator * (const point &a,const double &b) {return point (a.x*b,a.y*b);    } Friend point operator * (const double &a,const point &b) {return point (A*B.X,A*B.Y);    } Friend point operator/(const point &a,const double &b) {return point (a.x/b,a.y/b);    } double norm () {return sqrt (SQR (x) +sqr (y));    }//to Origin distance void out () const {printf ("%.2f%.2f", x, y); }} p[505];d ouble det (const point &a,const point &b) {return a.x*b.y-a.y*b.x;} Cross product double dot (const point &a,const point &b) {return a.x*b.x+a.y*b.y;} Click Multiply Double dist (const point &a,const-&b) {return (A-B). Norm (); Distance point Rotate_point (const point &p,double A) {double tx=p.X,TY=P.Y; Return Point (Tx*cos (a)-ty*sin (a), Tx*sin (a) +ty*cos (a));    Rotation, A is radian struct polygon_convex{vector <point> P;    Polygon_convex (int size=0) {p.resize (size); }} p_c;bool comp_less (const point &a,const point &b) {return CMP (a.x-b.x) <0| | CMP (a.x-b.x) ==0&&cmp (A.Y-B.Y) <0;}    Polygon_convex convex_hull (Vector <point> a) {Polygon_convex res (2*a.size () +5);    Sort (A.begin (), A.end (), comp_less);    A.erase (Unique (A.begin (), A.end ()), A.end ());    int m=0; for (int i=0; I<a.size (), i++) {while (m>1 && CMP (det (res. P[m-1]-res. P[m-2],a[i]-res.        P[m-2]) <0) m--; Res.    P[m++]=a[i];    } int k=m; for (int i=int (A.size ())-2, i>=0; i--) {while (m>k && CMP (det (res). P[m-1]-res. P[m-2],a[i]-res.        P[m-2]) <0) m--; Res.    P[m++]=a[i]; } res.    P.resize (m); if (A.size () >1) Res.    P.resize (m-1); return res;} BOOL Cmp3 (point A,point b) {return a.x<b. x| | ((a.x==b.x) && (A.Y&LT;B.Y));}    int main () {int t,tt=0;        while (scanf ("%d", &t)) {tt++;        vector<point>pp;        Pp.clear ();        memset (vis,0,sizeof (VIS));        if (t==0) break;        int pos=-1;        int max_v=0;            for (int i=1; i<=t; i++) {scanf ("%d%d%d", &x[i],&y[i],&v[i]);        if (V[i]>max_v) max_v=v[i];        } int top=0;                for (int i=1; i<=t; i++) {if (V[i]==max_v) {p[top].x= (double) x[i];                P[top].y= (double) y[i];                P[top].pos=i;                p[top].o=0;            top++;        }} printf ("Case #%d:", TT);            if (max_v==0) {for (int i=1; i<=t; i++) printf ("0");            printf ("\ n");        Continue        } sort (P,p+top,cmp3); for (int i=0; i<top; i++) {if (I<top-1&&(p [i].x] = = (p[i+1].x) && (p[i].y) = = (p[i+1].y)) | |                (i>0&& (p[i].x) = = (p[i-1].x) && (p[i].y) = = (P[I-1].Y)))        P[i].o=1;        } pp.push_back (P[0]); for (int i=1; i<top; i++) {if (p[i].x!=p[i-1].x| |        P[I].Y!=P[I-1].Y) Pp.push_back (P[i]);                    if (Pp.size () <=3) {for (int i=0; i<pp.size (); i++) if (pp[i].o==0)        Vis[pp[i].pos]=1;            } else {Polygon_convex ans=convex_hull (PP); for (int i=0; I<ans. P.size (); i++) {//cout<<ans. p[i].ok<< "" <<ans.                p[i].pos<<endl; if (ans. p[i].o==0) Vis[ans.            P[i].pos]=1;        }} for (int i=1; i<=t; i++) printf ("%d", vis[i]);    printf ("\ n"); } return 0;} /*32 2 32 2 32 3 361 1 31-1 32 0 3-1 1 3-1-1 3-2 0 341 1 11 2 11 3 11 4 1151 1 01 1 12 1 13 1 14 1 15 115 2 15 3 15 4 14 4 13 4 12 4 11 4 11 3 11 2 191 4 11 3 11 2 11 1 12 1 13 1 14 1 13 2 12 3 1*/ 



HDU 4948 Kingdom

It was a pity when the game was over. I read the question. And then thought it was quite simple.

Just start a look at the question, think of is the topological sort. And then I think. The feeling is the reverse order of the topological sort. And found the water ...

As said to want to develop a city, there must be a city as a precondition for its development, that is, the city u->w such a link, said to want to develop the city W, if you are already a developed city. That's not very easy to say.

That is, the most statistical out of the city is the first to develop. Because u->w such a side can see the calculation of the most in order from large to small sort can be.

Oh. It's just a pity. Because I saw no one to hand this question. Then I don't dare to tell my teammates what I want to do, and then I don't knock myself ... Then missed the first version of the opportunity to really be the first echelon of the wrong way was the pit ...

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <map > #include <queue> #include <set> #include <cmath> #include <bitset> #define MEM (A, B) memset (a , B,sizeof (a)) #define Lson i<<1,l,mid#define Rson i<<1|1,mid+1,r#define Llson j<<1,l,mid#define Rrson j<<1|1,mid+1,r#define INF 0x7fffffff#define maxn 11010using namespace Std;typedef long Long ll;typedef unsign    Ed Long long Ull;char s[500][505];struct abc{int i,out;    BOOL operator< (CONST ABC &a) const {return out>a.out;    }}a[501];int Main () {//freopen ("1.txt", "R", stdin);    int n,i,j;        while (scanf ("%d", &n) &&n) {for (i=0;i<n;i++) scanf ("%s", S[i]), a[i].i=i,a[i].out=0;        for (i=0;i<n;i++) for (j=0;j<n;j++) if (s[i][j]== ' 1 ') a[i].out++;        Sort (a,a+n);        printf ("%d", a[0].i+1); for (i=1;i<n;i++) printf ("%d", a[i].i+1);    Puts (""); } return 0;}

HDU 4951 Multiplication Table

Multiplication table.

Look at each line. The two numbers are equal to 0.

Then look at the first unequal number, how many different is which number.

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <map > #include <queue> #include <set> #include <cmath> #include <bitset> #define MEM (A, B) memset (a , B,sizeof (a)) #define Lson i<<1,l,mid#define Rson i<<1|1,mid+1,r#define Llson j<<1,l,mid#define Rrson j<<1|1,mid+1,r#define INF 0x7fffffff#define maxn 11010using namespace Std;typedef long Long ll;typedef unsign    Ed Long Long Ull;int A[511][1011],vis[511];int main () {//freopen ("1.txt", "R", stdin);    int n,i,j,ii=1;        while (scanf ("%d", &n) &&n) {int flag,b[512]; for (i=0; i<n; i++) {for (j=0,flag=0; j<n; J + +) {scanf ("%d%d", &a[i][                J&LT;&LT;1],&AMP;A[I][J&LT;&LT;1|1]);            if (a[i][j<<1]!=a[i][j<<1|1]) flag++;        } if (!flag) b[0]=i;            } for (i=0;i<n;i++) {if (i==b[0]) continue; Mem (Vis, 0);            int sum=0;            For (j=0;j< (n<<1); j+=2) if (!vis[a[i][j]]) sum++,vis[a[i][j]]=1;        B[sum]=i;        } printf ("Case #%d:%d", ii++,b[0]);        for (i=1;i<n;i++) printf ("%d", b[i]);    Puts (""); } return 0;}

HDU 4952

pid=1008&cid=509 "style=" Color:rgb (26,92,200); Text-decoration:none; Font-family:tahoma; Background-color:rgb (215,235,255) ">number transformation

This problem, the output of the previous 100 values and multiples will be found in the next multiples are the same, multiples is the same every time the same number to the last, this word becomes a simple multiplication.

The three sentences of staring in the code are used to find patterns.

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <map > #include <queue> #include <set> #include <cmath> #include <bitset> #define MEM (A, B) memset (a , B,sizeof (a)) #define Lson i<<1,l,mid#define Rson i<<1|1,mid+1,r#define INF 10000010#define maxn 80010using    Namespace Std;typedef long long ll;typedef unsigned long long ull;int main () {ll n,m;    int Ans=1; while (scanf ("%i64d%i64d", &n,&m) && (n| |        m)) {//int cnt=0;        ll A=-1,b=-1,sum=0,i;        int flag=0;                for (i=2ll;i<=m;i++) {if (n%i) {b=n/i+1ll;                N=b*i; if (cnt++<100)//cout<< "+ + +" <<n<< "<< (int) (n/i) << ' <<i<<en                dl                if (b==a) break;                else a=b;            flag=1;   }} if (flag&&i<m) {sum=m-i;         Sum=sum*a+n;        } else sum=n;    printf ("Case #%d:%i64d\n", ans++,sum); } return 0;}



Multi-eighth Field School: Geometry + graph theory + simulation + Find law

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.