CDOJ 1262 Memory

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

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

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

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

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

Input

一行一个整数n(2≤n≤52)

Output

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

题解

暴力

主要是意识到使序列中任意两个元素之和不等

下面的代码还是2比较好的感觉……(尤其是红色字体,很实用的技巧)

#include<stdio.h>
#include<algorithm>
#include<set>

using namespace std;

int main(void)
{
    int n;
    int b[60];
    int cnt,temp;
    int i,j;
    set <int> s;

    scanf("%d",&n);
    b[1]=1;
    b[2]=2;
    s.insert(3);
    cnt=3;

    for (i=3;i<=n;++i)
    {
        while (true)
        {
            temp=1;
            for (j=1;j<=i-1;++j)
            {
                if (s.count(b[j]+cnt))
                {
                    ++cnt;
                    temp=0;
                    break;
                }
            }
            if (temp==1)
            {
                b[i]=cnt;
                for (j=1;j<=i-1;++j) s.insert(b[j]+cnt);
                ++cnt;
                break;
            }
        }
    }

    if (n==2) printf("1 1");
    else
    {
        printf("%d",b[1]);
        for (i=2;i<=n;++i) printf(" %d",b[i]);
    }

}
#include<stdio.h>
#include<algorithm>
#include<set>

using namespace std;

int b[60];
set <int> s;

bool check(int j,int cnt);

int main(void)
{
    int n;
    int cnt;

    scanf("%d",&n);
    b[1]=1;
    b[2]=2;
    s.insert(3);
    cnt=3;

    for (int j=3;cnt<=n;++j)
    {
        if (check(j,cnt))
        {
            b[cnt]=j;
            for (int k=1;k<=cnt-1;++k) s.insert(j+b[k]);
            ++cnt;
        }
    }

    if (n==2) printf("1 1");
    else
    {
        printf("%d",b[1]);
        for (int i=2;i<=n;++i) printf(" %d",b[i]);
    }
}

bool check (int j,int cnt)
{
    for (int i=1;i<=cnt-1;++i)
    {
        if (s.count(b[i]+j)) return false;
    }
    return true;
}
时间: 2024-08-07 12:26:27

CDOJ 1262 Memory的相关文章

Memory

A - Memory Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Submit Status Practice UESTC 1262 Description 小x和小h是好盆友,小h从小体弱多病,而且还非常健忘,于是把自己平时吃的n瓶药都给小x等人保管. 某一天由于雾都的pm2.5爆表,小h的慢性呼吸道疾病又发作了,但当小x掏出药瓶的时候,却发现了异常情况. 小x现在有n瓶药,每瓶药里面有无

HDU 1262 寻找素数对

寻找素数对 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7750    Accepted Submission(s): 3871 Problem Description 哥德巴赫猜想大家都知道一点吧.我们现在不是想证明这个结论,而是想在程序语言内部能够表示的数集中,任意取出一个偶数,来寻找两个素数,使得其和等于该偶数. 做好了这件实

cdoj 1489 老司机采花

地址:http://acm.uestc.edu.cn/#/problem/show/1489 题目: 老司机采花 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit Status 老司机是一个武功高强,飞檐走壁的采花大盗,特别喜欢采花!一天,某组织想求老司机盗取一件神秘宝物,所以为了讨好老司机而特意安排了一场采花会.该采花会只能摆n朵花(花的颜色有10种可供选择,颜色

【暑假】[数学]UVa 1262 Password

UVa 1262  Password 题目: Password Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description Shoulder-surfing is the behavior of intentionally and stealthily watching the screen of another person's electronic de

cdoj 93 King&#39;s Sanctuary 傻逼几何题

King's Sanctuary Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/93 Description The king found his adherents were building four sanctuaries for him. He is interested about the positions of the sanctuaries and want

UVA 1262 Password 暴力枚举

Password Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVA. Original ID: 1262 64-bit integer IO format: %lld      Java class name: Main Prev Submit Status Statistics Discuss Next [PDF Link] Shoulder-surfing is the behavior

CDOJ 93 King&#39;s Sanctuary【判断四边形形状】

King's Sanctuary Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit  Status The king found his adherents were building four sanctuaries for him. He is interested about the positions of the sanctuaries and wants

Linux 性能监控 : CPU 、Memory 、 IO 、Network

一.CPU 1.良好状态指标 CPU利用率:User Time <= 70%,System Time <= 35%,User Time + System Time <= 70% 上下文切换:与CPU利用率相关联,如果CPU利用率状态良好,大量的上下文切换也是可以接受的 可运行队列:每个处理器的可运行队列<=3个线程 2.监控工具 vmstat $ vmstat 1 procs -----------memory---------- ---swap-- -----io---- --s

Java系列: 如何在Eclipse中安装Memory Analyzer插件

一.找到eclipse的插件安装对话框: help->install new software ->work with 二.输入Memory Analyzer的安装路径 具体可以到http://www.eclipse.org/mat/downloads.php 去找 我安装的时候的版本是1.6.1,如下 三.开始安装     null