2015 C Language Program design Competition (senior group), Jiangxi University of Technology

Source: Internet
Author: User
Tags cmath

A

Solution: dp+ two points

Dp[i]=max (DP[I],DP[J]+P[I].V) (I>J)

Dp[i] Indicates the maximum value that can be obtained after the establishment of the I point

intn,m;structnode{intL,v;} p[1010];intdp[1010];BOOLCMP (node A,node b) {returnA.L <B.L;}BOOLJudge_oo () {intMax =-1;  for(inti =1; I <= n;i++) Max =Max (MAX,P[I].V); if(Max >= M)return 1; return 0;}BOOLJudge_no () {intsum =0;  for(inti =1; I <= n;i++) sum + =p[i].v; if(Sum >= M)return 0; return 1;}BOOLJUDGE_DP (intL) {memset (DP,0,sizeofDP);  for(inti =1; I <= n;i++){         for(intj =0; J < I; J + +){            if(P[i].l-p[j].l >=L) {Dp[i]= Max (Dp[i],dp[j] +p[i].v); }        }    }    intML =0;  for(inti =1; I <= n;i++) ML =Max (ml,dp[i]); if(ML >= M)return 1; return 0;}intSolveintLintR) {     while(L +1<R) {        intMid = (L + R)/2; if(JUDGE_DP (mid)) L =mid; ElseR =mid; }    returnL;}intMainintargcChar*argv[]) {    //freopen ("data.in", "R", stdin); //freopen ("Data.out", "w", stdout);    intT; CIN>>T;  while(t--) {cin>> N >>M;  for(inti =1; I <= N;i + +) Cin>> P[I].L >>p[i].v; if(Judge_no ()) {puts ("-1"); Continue; }        if(Judge_oo ()) {puts ("oo"); Continue; } sort (P+1, p+n+1, CMP); p[0].L =-100000000, p[0].V =0; intL =1, R =P[N].L; cout<< Solve (l,r) <<Endl; }    return 0;}
B

Solution: Simulation. String emulation

#include <stdio.h>//#include <bits/stdc++.h> #include <string.h> #include <iostream> #include <math.h> #include <sstream> #include <set> #include <queue> #include <map> #include < vector> #include <algorithm> #include <limits.h> #define INF 0x3fffffff#define inf 0x3f3f3f3f#define Lson L,m,rt<<1#define Rson m+1,r,rt<<1|1#define LL long long#define ULL unsigned long longusing namespace Std;int I , J;int n,m;int num_1,num_2;int t;int sum,ans,flag;string s_1,s_2,s_3;string sss;string ss[10000];string c;map<    String,int>q1;map<string,int>q2;int Main () {cin>>t;        while (t--) {cin>>n>>c;        num_1=0;            for (i=0; i<n; i++) {cin>>sss;            Ans=sss.find (".");            S_1=sss.substr (0,ans);            S_2=sss.substr (Ans+1,sss.length ());                if (s_2==c) {int ans_2=sss.find (");      int Ans_3=sss.find (")");          if ((Ans_2!=-1&&ans_2<ans_3)) {//num_1++;                    Ss[num_1++]=sss.substr (0,ans_2);                Cout<<sss.substr (0,ans_2) <<endl; } else if (ans_2==-1| |                    ANS_3==-1) {//num_1++;                    Ss[num_1++]=sss.substr (0,ans);                Cout<<sss.substr (0,ans) <<endl; }}} for (i=0; i<num_1; i++) {//cout<<ss[i]<< "A" <<e        Ndl        }//cout<<num_1<<endl;        for (i=0; i<num_1; i++) {q1[ss[i]]++;                } for (i=0; i<num_1; i++) {if (q2[ss[i]]==0) {q2[ss[i]]=1; if (q1[ss[i]]==1) {cout<<ss[i]<< "."                <<c<<endl;  } else {                  cout<<ss[i]<< "."                <<c<< "" <<q1[ss[i]]<<endl;        }}} q1.clear ();    Q2.clear (); } return 0;}
C

Solution: Tree-like array looking for reverse-order + preprocessing

#include <cstdio>#include<iostream>#include<algorithm>#include<cstring>#include<cmath>using namespacestd;Const intM =200010;Long LongAns[m +Ten];intG[m +Ten],c[m +Ten];intLowbit (intx) {    returnX & (-x);}voidInsert (intXintFD) {     while(x<=M) {C[x]+=D; X+=lowbit (x); }}intSum (intx) {    intsum=0;  while(x>0) {sum+=C[x]; X-=lowbit (x); }    returnsum;}voidinit () {memset (G,-1,sizeofG); memset (ans,0,sizeofans); Memset (c,0,sizeofc); g[1] =1;  for(inti =2; I <=200100; i++){        if(G[i] = =-1){             for(intj = I;j <=200100; J + =i) {                if(G[j] = =-1) {G[j]=i; }            }        }    }     for(intI=1; i<=200005; i++) {Insert (g[i],1); Ans[i]= ans[i-1] + (I-Sum (G[i])); }}intMain () {init (); intT; CIN>>T;  while(t--)    {        intN; CIN>>N; cout<<ans[n]<<Endl; }    return 0;}
D

Solution: Template problem, minimum cover circle

#include <iostream>#include<cmath>#include<cstdio>#include<algorithm>using namespacestd;Const Doubleeps=1e-8;structpoint{Doublex, y;} p[505];DoubleDisConstPoint &a,ConstPoint &b) {    returnsqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (a.y-b.y));} Point Circumcenter (ConstPoint &a,ConstPoint &b,ConstPoint &c) { //returns the circumcenter of a trianglePoint ret; Doublea1=b.x-a.x,b1=b.y-a.y,c1= (A1*A1+B1*B1)/2; DoubleA2=c.x-a.x,b2=c.y-a.y,c2= (A2*A2+B2*B2)/2; Doubled=a1*b2-a2*B1; Ret.x=a.x+ (C1*B2-C2*B1)/D; Ret.y=a.y+ (A1*C2-A2*C1)/D; returnret;}voidMin_cover_circle (Point *p,intN,point &c,Double&r) {//c is the center and R is the radiusRandom_shuffle (P,p+n);//c=p[0]; R=0;  for(intI=1; i<n;i++)    {        if(Dis (p[i],c) >r+eps)//First Point{C=p[i]; R=0;  for(intj=0; j<i;j++)                if(Dis (p[j],c) >r+eps)//a second point{c.x= (p[i].x+p[j].x)/2; C.y= (P[I].Y+P[J].Y)/2; R=dis (p[j],c);  for(intk=0; k<j;k++)                        if(Dis (p[k],c) >r+eps)//a third point{//Ask Circumscribed Circle Center, three points must not collinearC=circumcenter (P[i],p[j],p[k]); R=dis (p[i],c); }                }        }    }}intMain () {intN;    Point C; DoubleR; intT; CIN>>T;  while(t--) {cin>>N;  for(intI=0; i<n; i++) scanf ("%LF%LF",&p[i].x,&p[i].y);        Min_cover_circle (P,N,C,R); printf ("%.1f%.1f\n", C.X,C.Y); }     return 0;}

2015 C Language Program design Competition (senior group), Jiangxi University of Technology

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.