• Memory


    A - Memory
    Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu

    Description

    小x和小h是好盆友,小h从小体弱多病,而且还非常健忘,于是把自己平时吃的n瓶药都给小x等人保管。

    某一天由于雾都的pm2.5爆表,小h的慢性呼吸道疾病又发作了,但当小x掏出药瓶的时候,却发现了异常情况。

    小x现在有n瓶药,每瓶药里面有无限个药片,每片药重量严格等于1克。但是,吹毛求疵的小x发现n瓶药中有2瓶药的每一片药片在重量上是不合格的,不合格的药片比正常药片轻0.1g。

    小x现在有一个电子称(能够显示具体重量),由于时间紧急,小x决定从每瓶药中选择bi(1bi)个药片,称量它们的总和,并且只称一次,从而找出这两瓶不合格药的编号。

    现在,请问最小字典序的序列b(bi构成)是多少?

    Input

    一行一个整数n(2n52)

    Output

    一行n个数字,两两间用空格隔开,注意结尾没有空格。

    Sample Input

    3

    Sample Output

    1 2 3

    直接暴力即可。

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    #include <cmath>
    #include <map>
    using namespace std;
    int a[60];
    map<int,int> vis;
    int main()
    {
        int n;
        scanf("%d",&n);
        a[1] = 1;
        a[2] = 2;
        vis[3] = 1;
        if(n==2) printf("1 1
    ");
        else
        {
           for(int i=3;i<=n;i++)
           {
               int flag = 0;
               for(int j=a[i-1]+1;j<=10050&&!flag;j++)
               {
                   int temp = j;
                   int flag1 = 0;
                   for(int k=1;k<i;k++)
                   {
                       if(vis[temp+a[k]])
                       {
                           flag1 = 1;
                           break;
                       }
                   }
                   if(!flag1)
                   {
                       for(int k=1;k<i;k++)
                       {
                           vis[temp+a[k]] = 1;
                       }
                       flag = 1;
                       a[i] = temp;
                   }
               }
           }
           printf("%d",a[1]);
           for(int i=2;i<=n;i++) printf(" %d",a[i]);
           printf("
    ");
        }
        return 0;
    }
  • 相关阅读:
    605. Can Place Flowers
    1184. Distance Between Bus Stops
    1711. Count Good Meals
    1710. Maximum Units on a Truck
    566. Reshape the Matrix
    980. Unique Paths III
    212. Word Search II
    每日总结
    每日总结
    每日总结
  • 原文地址:https://www.cnblogs.com/littlepear/p/5785823.html
Copyright © 2020-2023  润新知