zoukankan      html  css  js  c++  java
  • Codeforces Round #208 (Div. 2)

    A - Dima and Continuous Line

    水题:直接模拟;

     1 #include<cstdio>
     2 #define maxn 1005
     3 using namespace std;
     4 int x[maxn],y[maxn];
     5 int main()
     6 {
     7     int n,a,b,last;
     8     scanf("%d",&n);
     9     bool flag=1;
    10     for(int i=0;i<n;i++)
    11     {
    12         scanf("%d",&b);
    13         a=last;
    14         last=b;
    15         if(i==0)continue;
    16         if(a>b)
    17         {
    18             a=a^b;
    19             b=a^b;
    20             a=a^b;
    21         }
    22         if(flag)
    23         for(int j=0;j<i;j++)
    24         {
    25             if((a>x[j]&&a<y[j]&&b>y[j])||(x[j]>a&&b>x[j]&&y[j]>b))
    26                 flag=0;
    27         }
    28         x[i]=a;
    29         y[i]=b;
    30     }
    31     if(flag==0)puts("yes");
    32     else puts("no");
    33     return 0;
    34 }
    View Code

    B - Dima and Text Messages

    水题:按照顺序找就行了

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<cstring>
     4 #include<string>
     5 #define maxn 100005
     6 using namespace std;
     7 string s,t,c;
     8 int main()
     9 {
    10     int n;
    11     scanf("%d",&n);
    12     s="<3";
    13     for(int i=0;i<n;i++)
    14     {
    15         cin>>c;
    16         s+=c;
    17         s+="<3";
    18     }
    19     cin>>t;
    20     int j=0;
    21     int l=s.size();
    22     int m=t.size();
    23     for(int i=0;i<m;i++)
    24     {
    25         if(s[j]==t[i])
    26         {
    27             j++;
    28             if(j==l)break;
    29         }
    30     }
    31     if(j==l)puts("yes");
    32     else puts("no");
    33     return 0;
    34 }
    View Code

    C - Dima and Containers

    水题:直接模拟,三个容器每个放一个大的,其他小的都放在deck的另一边;

     1 #include<cstdio>
     2 #include<algorithm>
     3 #define maxn 100005
     4 using namespace std;
     5 
     6 struct node
     7 {
     8     int id;
     9     int num;
    10     bool operator<(const node &t)const
    11     {
    12         return num<t.num;
    13     }
    14 }no[maxn];
    15 
    16 int ans[maxn];
    17 
    18 char s[20][30]={"pushStack","pushQueue","pushFront","pushBack","0","popStack","popStack popQueue","popStack popQueue popFront"};
    19 int main()
    20 {
    21     int n;
    22     scanf("%d",&n);
    23     for(int i=0;i<n;i++)
    24     {
    25         scanf("%d",&no[i].num);
    26         no[i].id=i;
    27     }
    28     int j=0;
    29     for(int i=0;i<n;i++)
    30     {
    31         if(no[i].num==0&&i!=j)
    32         {
    33             int cnt=0;
    34             sort(no+j,no+i);
    35 //            for(int k=j;k<=i-1;k++)
    36 //                printf("%d<
    ",no[k].num);
    37             ans[no[i-1].id]=0;
    38             cnt++;
    39             if(i-2>=j){ans[no[i-2].id]=1;cnt++;}
    40             if(i-3>=j){ans[no[i-3].id]=2;cnt++;}
    41             if(i-4>=j)
    42             {
    43                 for(int k=j;k<=i-4;k++)
    44                     ans[no[k].id]=3;
    45             }
    46             if(cnt==1)ans[i]=5;
    47             if(cnt==2)ans[i]=6;
    48             if(cnt==3)ans[i]=7;
    49             j=i+1;
    50         }
    51         else if(no[i].num==0&&i==j){ans[i]=4;j++;}
    52     }
    53     for(int i=0;i<n;i++)
    54     {
    55         if(ans[i]<5)puts(s[ans[i]]);
    56         else printf("%d %s
    ",ans[i]-4,s[ans[i]]);
    57     }
    58     return 0;
    59 }
    View Code

    D - Dima and Hares

    dp:

    这个题挺不错的;

    before[i]代表第i个兔子比它前面的那个先喂;

    after[i]代表第i个兔子比它前面那个后喂;

    然后扫一遍就行,注意边界条件

     1 #include<cstdio>
     2 #include<algorithm>
     3 #define maxn 3005
     4 using namespace std;
     5 
     6 int map[3][maxn];
     7 int before[maxn],after[maxn];
     8 
     9 int main()
    10 {
    11     int n;
    12     scanf("%d",&n);
    13     for(int i=1;i<=n;i++)
    14         scanf("%d",&map[0][i]);
    15     for(int i=1;i<=n;i++)
    16         scanf("%d",&map[1][i]);
    17     for(int i=1;i<=n;i++)
    18         scanf("%d",&map[2][i]);
    19     before[1]=0;
    20     after[1]=-9999999;
    21     for(int i=2;i<=n+1;i++)
    22     {
    23         before[i]=max(before[i-1]+map[1][i-1],after[i-1]+map[2][i-1]);
    24         after[i]=max(before[i-1]+map[0][i-1],after[i-1]+map[1][i-1]);
    25     }
    26     printf("%d
    ",after[n+1]);
    27     return 0;
    28 }
    View Code
  • 相关阅读:
    Codeforces 1291 Round #616 (Div. 2) B
    总结
    刷新DNS解析缓存+追踪+域名解析命令
    数学--数论--Hdu 5793 A Boring Question (打表+逆元)
    Lucene.net(4.8.0) 学习问题记录六:Lucene 的索引系统和搜索过程分析
    LeetCode 117 Populating Next Right Pointers in Each Node II
    LeetCode 116 Populating Next Right Pointers in Each Node
    test test
    LeetCode 115 Distinct Subsequences
    LeetCode 114. Flatten Binary Tree to Linked List
  • 原文地址:https://www.cnblogs.com/yours1103/p/3417557.html
Copyright © 2011-2022 走看看