zoukankan      html  css  js  c++  java
  • 8月22日小练

    网站:8月21日小练

    A   Find the Shortest Common Superstring     HDU 1841

    B   免费馅饼     HDU 1176    DP

    思路:从时间后往前推,dp[i][j]表示在i,j地能接到的最多的馅饼数。

    代码:      46ms

     1 #include <stdio.h>
     2 #include <iostream>
     3 #include <string.h>
     4 using namespace std;
     5 int dp[100005][12];
     6 int max(int a,int b,int c)
     7 {
     8     return a>b?(a>c?a:c):(b>c?b:c);
     9 }
    10 int main()
    11 {
    12     int n,i,x,t,maxx,j;
    13     while(~scanf("%d",&n)&&n)
    14     {
    15         memset(dp,0,sizeof(dp));
    16         maxx=-1;
    17         for(i=1;i<=n;i++)
    18         {
    19             scanf("%d %d",&x,&t);
    20             maxx=max(maxx,t);
    21             dp[t][x]++;//在t秒x地的馅饼+1
    22         }
    23         for(i=maxx-1;i>=0;i--)   //从后往前推
    24         {
    25             dp[i][0]+=max(dp[i+1][0],dp[i+1][1]);
    26             for(j=1;j<=10;j++)
    27                 dp[i][j]+=max(dp[i+1][j],dp[i+1][j+1],dp[i+1][j-1]);
    28         }
    29         printf("%d
    ",dp[0][5]);//dp[0][5]是起点状态
    30     }
    31     return 0;
    32 }

    C     Lowest Bit    HDU 1196    水题,不解释

    代码: 0ms

     1 #include <stdio.h>
     2 #include <iostream>
     3 using namespace std;
     4 int main()
     5 {
     6     int n;
     7     while(~scanf("%d",&n)&&n)
     8     {
     9         printf("%d
    ",n&(-n));
    10     }
    11     return 0;
    12 }

    D  迷宫城堡    HDU 1269

    E   Optimal Parking   HDU 1673   水题,不解释

    代码:   0ms

     1 #include <stdio.h>
     2 #include <iostream>
     3 #include <string.h>
     4 #include <algorithm>
     5 using namespace std;
     6 int a[22];
     7 int main()
     8 {
     9     int T;
    10     scanf("%d",&T);
    11     while(T--)
    12     {
    13         int n,i,sum;
    14         scanf("%d",&n);
    15         for(i=1;i<=n;i++)
    16             scanf("%d",&a[i]);
    17         sort(a+1,a+1+n);
    18         sum=(a[n]-a[1])*2;
    19         printf("%d
    ",sum);
    20     }
    21     return 0;
    22 }
    View Code
  • 相关阅读:
    如何实现基于消息安全验证机制下的username身份验证过程
    Stooge 排序
    严版数据结构题集2.13 & 2.14
    Gnome排序
    严版数据结构题集2.11
    梳排序
    鸡尾酒排序
    C语言如何产生随机数
    Bogo排序
    快排序
  • 原文地址:https://www.cnblogs.com/riddle/p/3278705.html
Copyright © 2011-2022 走看看