zoukankan      html  css  js  c++  java
  • ACM 第十七天

    暑期热身赛

    BAPC 2014
    The 2014 Benelux Algorithm Programming Contest
     
    B Button Bashing
     1 #include<stdio.h>
     2 #include<bits/stdc++.h>
     3 #include<algorithm>
     4 #include<math.h>
     5 #include<string.h>
     6 #include<queue>
     7 using namespace std;
     8 
     9 const int inf=999999999;
    10 int a[20];
    11 int vis[4000];
    12 int tim,step,n,m;
    13 struct Node
    14 {
    15     int step,time;
    16 };
    17 
    18 void bfs()
    19 {
    20     queue <Node> q;
    21     Node s;
    22 
    23     s.step=s.time=0;
    24     vis[0]=1;
    25     q.push(s);
    26     while(!q.empty())
    27     {
    28         Node now=q.front();
    29         q.pop();
    30         if(now.time>=m)
    31         {
    32             int temp=now.time-m;
    33             if(temp==tim)
    34             {
    35                 step=min(now.step,step);
    36             }
    37             if(temp<tim)
    38             {
    39                 tim=temp;
    40                 step=now.step;
    41             }
    42         }
    43         for(int i=1; i<=n; i++)
    44         {
    45             Node next;
    46             next.step=now.step+1;
    47             next.time=now.time+a[i];
    48             if(next.time>3600)
    49             {
    50                 next.time=3600;
    51             }
    52             if(next.time>0 && !vis[next.time])
    53             {
    54                 vis[next.time]=1;
    55                 q.push(next);
    56             }
    57         }
    58     }
    59 }
    60 
    61 int main()
    62 {
    63 
    64     int t;
    65     cin>>t;
    66     while(t--)
    67     {
    68         cin>>n>>m;
    69         for(int i=0; i<=3900; i++)
    70             vis[i]=0;
    71         for(int i=1; i<=n; i++)
    72         {
    73             cin>>a[i];
    74         }
    75         tim=step=inf;
    76         if(m==0)
    77         {
    78             printf("0 0
    ");
    79             //continue;
    80         }
    81         else
    82         {
    83             bfs();
    84             printf("%d %d
    ",step,tim);
    85         }
    86     }
    87     return 0;
    88 }
     1 #include<iostream>
     2 #include<algorithm>
     3 #include<string>
     4 #include<stdio.h>
     5 #include<string.h>
     6 #define MAX 0x7f7f7f7f
     7 #define N 100004
     8 using namespace std;
     9 typedef long long LL;
    10 int cas,cass;
    11 int n,m,lll,ans;
    12 struct xxx
    13 {
    14     int x,y,z;
    15 } a[N];
    16 int t[N<<2];
    17 bool cmp(xxx aa,xxx bb)
    18 {
    19     return aa.x<bb.x;
    20 }
    21 void change(int l,int r,int x,int c,int k)
    22 {
    23     if(l>r || x<l || x>r)return;
    24     if(l==r)
    25     {
    26         t[k]=c;
    27         return;
    28     }
    29     change(l,(l+r)>>1,x,c,k+k);
    30     change((l+r)/2+1,r,x,c,k+k+1);
    31     t[k]=min(t[k+k],t[k+k+1]);
    32 }
    33 int query(int l,int r,int a,int b,int k)
    34 {
    35     if(l>r || l>b || r<a)return MAX;
    36     if(a<=l && r<=b)return t[k];
    37     int x1=query(l,(l+r)>>1,a,b,k+k),x2=query((l+r)/2+1,r,a,b,k+k+1);
    38     return t[k]=min(x1,x2);
    39 }
    40 int main()
    41 {
    42     int i,j,k;
    43     for(scanf("%d",&cas); cas; cas--)
    44 
    45     {
    46         ans=1;
    47         memset(t,0x7f,sizeof t);
    48         scanf("%d",&n);
    49         for(i=1; i<=n; i++)
    50             scanf("%d%d%d",&a[i].y,&a[i].z,&a[i].x);
    51         sort(a+1,a+1+n,cmp);
    52         change(1,n,a[1].y,a[1].z,1);
    53         for(i=2; i<=n; i++)
    54         {
    55             j=query(1,n,1,a[i].y,1);
    56             if(j>a[i].z)ans++;
    57             change(1,n,a[i].y,a[i].z,1);
    58         }
    59         printf("%d
    ",ans);
    60     }
    61     return 0;
    62 }
     1 #include<stdio.h>
     2 #include<bits/stdc++.h>
     3 #include<math.h>
     4 #include<algorithm>
     5 #include<string.h>
     6 using namespace std;
     7 
     8 int main()
     9 {
    10     int t,n;
    11     double a,b,c;
    12     cin>>t;
    13     while(t--)
    14     {
    15         cin>>n;
    16         int ans,shuchu;
    17         ans=0;
    18         double maxn=0;
    19         while(n--)
    20         {
    21 
    22             cin>>a>>b>>c;
    23             double q=(double)(c+(b*b)/(4*a));
    24             //cout<<q<<" ";
    25             ans++;
    26             if(q>maxn)
    27             {
    28                  shuchu=ans;
    29             }
    30             maxn=max(q,maxn);
    31 
    32         }
    33         cout<<shuchu<<endl;
    34     }
    35     return 0;
    36 }
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cmath>
     4 using namespace std;
     5 
     6 int main()
     7 {
     8     int t,n,x,y;
     9     int f[1005];
    10     f[1]=0;
    11     f[2]=1;
    12     int i=3;
    13     for(i=3; i<=46; i++)
    14     {
    15         f[i]=f[i-2]+f[i-1];
    16     }
    17 
    18     cin>>t;
    19     while(t--)
    20     {
    21         cin>>n;
    22         bool bb=1;
    23         for(i=46; i>2&&bb; i--)
    24         {
    25             for(int ty=1; ty<=1000000; ty++)
    26             {
    27                 if(ty*f[i]+f[i-1]>n)
    28                 {
    29                     break;
    30                 }
    31                 else if((n-ty*f[i])%f[i-1]==0 &&(n-ty*f[i])/f[i-1]<=ty)
    32                 {
    33                     y=ty;
    34                     x=(n-ty*f[i])/f[i-1];
    35                    bb=0;
    36                     break;
    37                 }
    38 
    39             }
    40 
    41        }
    42        cout<<x<<" "<<y<<endl;
    43     }
    44     return 0;
    45 }
      1 #include<stdio.h>
      2 #include<algorithm>
      3 #include<math.h>
      4 #include<queue>
      5 #include<string.h>
      6 #define Max(a,b) (a>b?a:b)
      7 #include<bits/stdc++.h>
      8 using namespace std;
      9 
     10 const int maxn=1e6;
     11 struct node
     12 {
     13     int x,y,p;
     14     node(int x=0,int y=0,int p=0):x(x),y(y),p(p) {}
     15 };
     16 char s[maxn],mp[205][105];
     17 
     18 int main()
     19 {
     20     int t,r,c;
     21     cin>>t;
     22     cout<<t<<endl;
     23 
     24     while(t--)
     25     {
     26         cin>>s;
     27         memset(mp,'#',sizeof mp);
     28         mp[101][0]='.';
     29         int minx=101,maxx=101,miny=0,maxy=0;
     30         node pi=node(101,0,0);
     31         for(int i=0; i<strlen(s); i++)
     32         {
     33             if(s[i]=='F')
     34             {
     35                 if(pi.p==0)
     36                     pi.y+=1;
     37                 if(pi.p==1)
     38                     pi.x-=1;
     39                 if(pi.p==2)
     40                     pi.y-=1;
     41                 if(pi.p==3)
     42                     pi.x+=1;
     43                 mp[pi.x][pi.y]='.';
     44             }
     45             else if(s[i]=='B')
     46             {
     47                 if(pi.p==0)
     48                     pi.y-=1;
     49                 if(pi.p==1)
     50                     pi.x+=1;
     51                 if(pi.p==2)
     52                     pi.y+=1;
     53                 if(pi.p==3)
     54                     pi.x-=1;
     55                 mp[pi.x][pi.y]='.';
     56                 pi.p=(pi.p+2)%4;
     57             }
     58             else if(s[i]=='L')
     59             {
     60                 if(pi.p==0)
     61                     pi.x-=1;
     62                 if(pi.p==1)
     63                     pi.y-=1;
     64                 if(pi.p==2)
     65                     pi.x+=1;
     66                 if(pi.p==3)
     67                     pi.y+=1;
     68                 mp[pi.x][pi.y]='.';
     69                 pi.p=(pi.p+1)%4;
     70             }
     71             else if(s[i]=='R')
     72             {
     73                 if(pi.p==0)
     74                     pi.x+=1;
     75                 if(pi.p==1)
     76                     pi.y+=1;
     77                 if(pi.p==2)
     78                     pi.x-=1;
     79                 if(pi.p==3)
     80                     pi.y-=1;
     81                 mp[pi.x][pi.y]='.';
     82                 pi.p=(pi.p+3)%4;
     83             }
     84             minx=min(minx,pi.x);
     85             maxx=max(maxx,pi.x);
     86             miny=min(miny,pi.y);
     87             maxy=max(maxy,pi.y);
     88 
     89         }
     90         cout<<(maxx-minx+3)<<' '<<(maxy-miny+2)<<endl;
     91         //cout<<maxy<<miny;
     92         for(int i=minx-1; i<=maxx+1; i++)
     93         {
     94             for(int j=0; j<=maxy+1; j++)
     95             {
     96                 printf("%c",mp[i][j]);
     97             }
     98             printf("
    ");
     99         }
    100 
    101     }
    102     return 0;
    103 }
  • 相关阅读:
    Java学习之内部类
    Java学习之方法内部类
    CTFHub:RCE命令注入
    C++ :string 用法详解
    oracle数据类型
    a[0]=1,a[1]=11,a[2]=21,a[3]=1211找出规律,输入下标,得出对应的值
    python计算登山队最远坐标
    子网掩码
    实现点赞功能
    获取评论数和细节处理
  • 原文地址:https://www.cnblogs.com/weixq351/p/9523135.html
Copyright © 2011-2022 走看看