바이두의 별 자격 경기 코드 전집:

64712 단어 바이두
각종 물문제야...
A:
#include<stdio.h>

int main()

{

    int a,b;

    while(scanf("%d%d",&a,&b)!=EOF)

    {

        printf("%d
",a+b); } return 0; }

 
 
B:
#include<stdio.h>

int main()

{

    int T;

    int n;

    int ans;

    int t;

    scanf("%d",&T);

    while(T--)

    {

        ans=0;

        scanf("%d",&n);

        for(int i=0;i<n;i++)

        {

            scanf("%d",&t);

            ans+=t;

        }   

        printf("%d
",ans+1-n); } return 0; }

 
 
C:
#include<stdio.h>

#include<iostream>

using namespace std;

double a[12];

int main()

{

    double sum=0;

    for(int i=0;i<12;i++)

    {

        scanf("%lf",&a[i]);

        sum+=a[i];

    }    

    printf("$%.2lf
",sum/12); // system("pause"); return 0; }

 
 
D:
#include<stdio.h>

#include<iostream>

using namespace std;

int main()

{

    int T;

    int h,m;

    scanf("%d",&T);

    while(T--)

    {

        scanf("%d:%d",&h,&m);

        if(m!=0) printf("0
"); else { int tmp=h+12; if(tmp>24) tmp%=24; printf("%d
",tmp); } } return 0; }

 
 
E:
#include<stdio.h>

#include<string.h>

#include<iostream>

using namespace std;

const int MAXN=110;

char str1[MAXN];

char str2[MAXN];

int main()

{

    bool flag1,flag2;

    while(scanf("%s",&str1)!=EOF)

    {

        flag1=true;

        flag2=true;

        int len1=strlen(str1);

        int len2=0;

        if(str1[0]<'a'||str1[0]>'z')

        {

            printf("Error!
"); continue; } for(int i=0;i<len1;i++) { if(str1[i]>='a'&&str1[i]<='z') continue; if(str1[i]=='_'&&i+1<len1&&str1[i+1]>='a'&&str1[i+1]<='z') { flag1=false; i++; continue; } if(str1[i]>='A'&&str1[i]<='Z') { flag2=false; continue; } flag1=false; flag2=false; break; } if(flag1==false&&flag2==false) { printf("Error!
"); continue; } if(flag1&&flag2) { printf("%s
",str1); continue; } if(flag1) //Java { for(int i=0;i<len1;i++) { if(str1[i]>='A'&&str1[i]<='Z') { str2[len2++]='_'; str2[len2++]=str1[i]-'A'+'a'; } else str2[len2++]=str1[i]; } } else { for(int i=0;i<len1;i++) { if(str1[i]=='_') { i++; str2[len2++]=str1[i]-'a'+'A'; } else str2[len2++]=str1[i]; } } str2[len2]='\0'; printf("%s
",str2); } return 0; }

 
 
F:
 #include<stdio.h>

 #include<memory.h>

 #include<stdlib.h>

  #define maxn 102

  int d[maxn],g[maxn][maxn],f[maxn][maxn],pre[maxn],map[maxn][maxn],sum[maxn],current[maxn];

  int n,m,num,mm;

  struct node

 {

     int x,y;

 }seg[1000],time[1000];

  #define oo 0xfffffff

  int cmp(const void *a,const void *b)

 {

     struct node *va=(struct node*)a;

     struct node *vb=(struct node*)b;

     return va->x-vb->x;

 }

  void rev_bfs(int t)

 {

     int queue[maxn],flag[maxn];

     int head,tail,i;

     memset(sum,0,sizeof(sum));

     for (i=0;i<=n+49;i++)

     {

         d[i]=n+49;

         sum[n+49]++;

     }

     sum[n+49]--;

     sum[0]++;

     d[t]=0;

     queue[1]=t;

     flag[t]=1;

     head=1;tail=1;

     memset(flag,0,sizeof(flag));

     while (head<=tail)

     {

         for (i=0;i<=n+49;i++)

             if (flag[i]==0&&g[i][queue[head]]>0)

             {

                 queue[++tail]=i;

                 d[i]=d[queue[head]]+1;

                 sum[n+49]--;

                 sum[d[i]]++;

                 flag[i]=1;

             }

         head++;

     }

 }

  void augment(int s,int t)

 {

     int i,min;

     min=oo;

     for (i=t;i!=s;i=pre[i])

          if (g[pre[i]][i]<min)

             min=g[pre[i]][i];

     for (i=t;i!=s;i=pre[i])

     {

         g[pre[i]][i]-=min;;

         g[i][pre[i]]+=min;

         f[pre[i]][i]+=min;

         f[i][pre[i]]-=min;

     }

 }

  int retreat(int *u,int s)

 {

     int v,min;

     min=n+49;

     for (v=0;v<=n+49;v++)

         if (g[*u][v]>0&&d[v]<min)

             min=d[v];

     sum[d[*u]]--;

     if ((sum[d[*u]])==0&&d[*u]<=n+49) return 0;

     d[*u]=min+1;

     sum[d[*u]]++;

     current[*u]=0;

     if (*u!=s) *u=pre[*u];

     return 1;

 }

  void ISAP(int s,int t)

 {

     int u,v;

     rev_bfs(t);

     u=s;

     while (d[s]<n+50)

     { 

         for (v=current[u];v<=n+49;v++)                                                                            

             if (g[u][v]>0&&d[u]==d[v]+1)

                 break;

         if (v<=n+49)

         {

             current[u]=v;

             pre[v]=u;

             u=v;

             if (u==t)

             {

                 augment(s,t);

                 u=s;

             }

         }

         else if (retreat(&u,s)==0) return;

     }

 }

 void init()

 {

     int i,j,a,b,c,d,min,t,k,ans,max,st,en,temp;

     while (scanf("%d",&n)!=EOF&&n)

     {

         memset(map,0,sizeof(map));;

         for (i=1;i<=n;i++)

         {

             scanf("%d%d",&m,&t);

             map[48][i+48]=t/30;

             num=0;

             mm=0;

             for (j=1;j<=m;j++)

             {

                 scanf("%d:%d %d:%d",&a,&b,&c,&d);

                 if (a==c&&b==d)

                 {

                     for (k=0;k<48;k++)

                         map[i+48][k]=1;

                     continue;

                 }

                 if (c==0&&d==0)

                 {

                     num++;

                     seg[num].x=a*60+b;

                     seg[num].y=1440;

                 }

                 else if (a*60+b>c*60+d)

                 {

                     num++;

                     seg[num].x=a*60+b;

                     seg[num].y=1440;

                     num++;

                     seg[num].x=0;

                     seg[num].y=c*60+d;

                 }

                 else

                 {

                     num++;

                     seg[num].x=a*60+b;

                     seg[num].y=c*60+d;

                 }

             }

             if (num==0) continue;

             qsort(seg+1,num,sizeof(seg[1]),cmp);

             st=seg[1].x;en=seg[1].y;

             seg[num+1].x=1500;seg[num+1].y=1600;

             for (j=2;j<=num+1;j++)

             {

                 a=seg[j].x;

                 b=seg[j].y;

                 if (st<=a&&a<=en&&en<b)

                     en=b;

                 else if (a>en)

                 {

                     mm++;

                     time[mm].x=st;

                     time[mm].y=en;

                     st=a;

                     en=b;

                 }

             }

             for (j=1;j<=mm;j++)

             {

                 a=time[j].x/60;

                 b=time[j].x-60*a;

                 c=time[j].y/60;

                 d=time[j].y-60*c;

                 if (a==c)

                 {

                     if (b==0&&d>=30)

                         map[i+48][a*2]=1;

                 }

                 else

                 {

                     if (b>0&&b<=30) b=30;

                     if (b>30) 

                     {

                         a++;

                         b=0;

                     }

                     if (d<30) d=0;

                     if (d>30) d=30;

                     while (a!=c||b!=d)

                     {

                         map[i+48][a*2+b/30]=1;

                         b+=30;

                         if (b==60)

                         {

                             a++;

                             b=0;

                         }

                     }

                 }

             }

         }

         max=oo;

         for (j=0;j<48;j++)

         {

             temp=0;

             for (k=49;k<n+49;k++)

                 if (map[k][j]>0) temp++;

             if (temp<max)

                 max=temp;

         }

         ans=0;

         for (j=1;j<=max;j++)

         {

             memset(g,0,sizeof(g));

             memset(f,0,sizeof(f));

             memset(current,0,sizeof(current));

             for (i=0;i<=49+n;i++)

                 for (k=0;k<=49+n;k++)

                     g[i][k]=map[i][k];

             for (i=0;i<48;i++)

                 g[i][n+49]=j;

             ISAP(48,n+49);

             min=oo;

             for (i=0;i<48;i++)

                 if (f[i][n+49]<min)

                     min=f[i][n+49];

             if (min>ans) ans=min;

         }

         printf("%d
",ans); } } int main() { init(); return 0; }

 
F의 신 코드:
#include <stdio.h>

int main(){

printf("1
2
1
2
0
0
2
1
2
3
3
2
2
3
1
1
2
2
3
1
1
25
7
4
47
50
41
0
3
2
7
4
4
5
0
6
3
2
2
1
0
4
6
6
3
0
3
9
15
10
3
16
14
11
8
13
0
6
5
33
33
33
32
31
35
33
32
28
25
32
27
30
30
31
2
2
4
4
4
3
3
4
4
3
5
0
5
3
0
17
14
15
16
14
14
14
17
15
14
15
14
15
14
14
11
14
13
11
13
18
6
16
6
24
14
14
14
14
14
14
14
14
14
14
14
14
14
14
14
"); }

 
 
G:
#include<stdio.h>

#include<string.h>

#include<iostream>

using namespace std;

char str[1000];

int main()

{

    while(cin.getline(str,1000))

    {

        printf("%s
",str); } return 0; }

 
 
H:
#include<stdio.h>

#include<string.h>

#include<stdlib.h>

#define MAXD 100010

#define INF 0x3f3f3f3f

char b[MAXD];

int N, r[MAXD], sa[MAXD], rank[MAXD], height[MAXD], wa[MAXD], wb[MAXD], ws[MAXD], wv[MAXD];

int best[20][MAXD], mm[MAXD], len[MAXD], first[MAXD], P;

void init()

{

    int i;

    for(i = 0; b[i]; i ++)

        r[i] = b[i];

    r[N = i] = 0;

}

int cmp(int *p, int x, int y, int l)

{

    return p[x] == p[y] && p[x + l] == p[y + l];

}

int cmp1(const void *_p, const void *_q)

{

    int i, *p = (int *)_p, *q = (int *)_q;

    for(i = 0; i < len[*p] && i < len[*q]; i ++)

    {

        if(r[first[*p] + i] < r[first[*q] + i])

            return -1;

        else if(r[first[*p] + i] > r[first[*q] + i])

            return 1;

    }

    if(i == len[*p])

        return -1;

    return 1;

}

void da(int n, int m)

{

    int i, j, p, *x = wa, *y = wb, *t;

    memset(ws, 0, sizeof(ws[0]) * m);

    for(i = 0; i < n; i ++)

        ++ ws[x[i] = r[i]];

    for(i = 1; i < m; i ++)

        ws[i] += ws[i - 1];

    for(i = n - 1; i >= 0; i --)

        sa[-- ws[x[i]]] = i;

    for(j = p = 1; p < n; j *= 2, m = p)

    {

        for(p = 0, i = n - j; i < n; i ++)

            y[p ++] = i;

        for(i = 0; i < n; i ++)

            if(sa[i] >= j)

                y[p ++] = sa[i] - j;

        for(i = 0; i < n; i ++)

            wv[i] = x[y[i]];

        memset(ws, 0, sizeof(ws[0]) * m);

        for(i = 0; i < n; i ++)

            ++ ws[wv[i]];

        for(i = 1; i < m; i ++)

            ws[i] += ws[i - 1];

        for(i = n - 1; i >= 0; i --)

            sa[-- ws[wv[i]]] = y[i];

        for(t = x, x = y, y = t, x[sa[0]] = 0, i = p = 1; i < n; i ++)

            x[sa[i]] = cmp(y, sa[i - 1], sa[i], j) ? p - 1 : p ++;

    }

}

void calheight(int n)

{

    int i, j, k = 0;

    for(i = 1; i <= n; i ++)

        rank[sa[i]] = i;

    for(i = 0; i < n; height[rank[i ++]] = k)

        for(k ? -- k : 0, j = sa[rank[i] - 1]; r[i + k] == r[j + k]; k ++);

}

void initRMQ(int n)

{

    int i, j, x, y;

    for(mm[0] = -1, i = 1; i <= n; i ++)

        mm[i] = (i & (i - 1)) == 0 ? mm[i - 1] + 1 : mm[i - 1];

    for(i = 1; i <= n; i ++)

        best[0][i] = i;

    for(i = 1; i <= mm[n]; i ++)

        for(j = 1; j <= n - (1 << i) + 1; j ++)

        {

            x = best[i - 1][j];

            y = best[i - 1][j + (1 << (i - 1))];

            best[i][j] = height[x] < height[y] ? x : y;

        }

}

int askRMQ(int x, int y)

{

    int t = mm[y - x + 1];

    y = y - (1 << t) + 1;

    x = best[t][x];

    y = best[t][y];

    return height[x] < height[y] ? height[x] : height[y];

}

int calculate(int x, int y)

{

    int t;

    x = rank[x], y = rank[y];

    if(x > y)

        t = x, x = y, y = t;

    ++ x;

    return askRMQ(x, y);

}

void printresult(int max)

{

    int i, j, k;

    if(max == 1)

    {

        k = INF;

        for(i = 0; i < N; i ++)

            if(r[i] < k)

                k = r[i];

        printf("%c
", k); } else { for(i = 0; i < P; i ++) ws[i] = i; qsort(ws, P, sizeof(ws[0]), cmp1); for(i = 0, k = ws[0]; i < len[k]; i ++) printf("%c", r[first[k] + i]); printf("
"); } } void solve() { int i, j, k, p, max = 1, ans; da(N + 1, 128); calheight(N); initRMQ(N); for(i = 1; i < N; i ++) for(j = 0; j + i < N; j += i) { ans = calculate(j, j + i); k = j - (i - ans % i); ans = ans / i + 1; if(ans < max - 1 || (ans == max - 1 && calculate(k, k + i) < i)) continue; for(k = ans == max - 1 ? k : j; j - k < i; k --) { ans = calculate(k, k + i); ans = ans / i + 1; if(ans < max) break; if(ans > max) { max = ans; P = 0; } first[P] = k, len[P] = ans * i; ++ P; } } printresult(max); } int main() { int t = 0; for(;;) { scanf("%s", b); if(b[0] == '#') break; printf("Case %d: ", ++ t); init(); solve(); } return 0; }

 
 
I:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<cstdlib>

#include<cassert>

#include<string>

#include<algorithm>

#include<fstream>

#include<sstream>

#include<set>

#include<map>

#include<vector>

#include<queue>

#include<deque>

#include<complex>

#include<numeric>

using namespace std;

double x[10], y[10], t[10];

bool solve(int i, int j, int k)

{

    double x1, y1, x2, y2, t1, t2;

    x1 = x[j] -x[i];

    x2 = x[k] -x[i];

    y1 = y[j] -y[i];

    y2 = y[k] -y[i];

    t1 = t[j] -t[i];

    t2 = t[k] -t[i];

    

    double A1 = x1*x1 + y1*y1 - t1*t1;

    double A2 = x2*x2 + y2*y2 - t2*t2;

    double A = A1*y2-A2*y1, B = A1*x2-A2*x1, C = A1 * t2 - A2 * t1;

    double cita = atan2(B, A);

    double sum = asin(- C/sqrt(A*A+B*B+1e-15));

    

    double alpha = sum - cita;

    double r;

    if (abs(A1)>abs(A2))

        r = A1/(t1 + x1 *cos(alpha) + y1 * sin(alpha))/2;

    else

        r = A2/(t2 + x2 *cos(alpha) + y2 * sin(alpha))/2;

    

    if (r<0)

    {

        sum = - sum + 3.141592653579;

        alpha = sum - cita;

        if (abs(A1)>abs(A2))

            r = A1/(t1 + x1 *cos(alpha) + y1 * sin(alpha))/2;

        else

            r = A2/(t2 + x2 *cos(alpha) + y2 * sin(alpha))/2;

    }

            

        

    printf("%.6f %.6f
", r * cos(alpha) + x[i], r * sin(alpha) + y[i]); } int main() { for (int dd = 1; ; ++ dd) { double c; scanf("%lf", & c); c/=1000; if (abs(c) < 1e-6) break; scanf("%lf %lf %lf %lf %lf %lf", x, y, x+1, y+1, x+2, y+2); scanf("%lf %lf %lf", t, t+1, t+2); printf("Case %d:
", dd); t[0] *= c; t[1] *= c; t[2] *= c; if (solve(0, 1, 2)) continue; } return 0; }

 
 
J
#include <cstdio>

#include <limits>

#include <algorithm>

using namespace std;



long long solve(int u, int d, int N)

{

  const long long m = (static_cast<long long>(N)*u-1LL)/(u+d);

  const long long n = N - m;

  return u*n - m*d;

}



int main()

{

  int N, M;

  scanf("%d %d", &N, &M);

  long long ans = numeric_limits<long long>::max();

  for (int i = 0; i < M; i++) {

    int u, d;

    scanf("%d %d", &u, &d);

    ans = min(ans, solve(u, d, N));

  }

  printf("%lld
", ans); return 0; }

 
 

좋은 웹페이지 즐겨찾기