codeforces 659C Tanya and Toys

题目链接:http://codeforces.com/problemset/problem/659/C

题意:

n是已经有的数字,m是可用的最大数字和

要求选自己没有的数字,且这些数字的数字和不能超过m

且要求可选的数字的数目越多越好

输出一种答案即可

解题思路:

刚开始想开一个bool型的1e9的数组,然后判断即可

可是交上去发现内存超限

后来把1e9的数组改成2*1e6的数组即可

具体原因应该从数学数字和方面考虑

具体代码如下:

#include<bits/stdc++.h>

using namespace std;

bool a[200006];

int main()
{
    int n,m,t;
    scanf("%d %d",&n,&m);
    for(int i=0;i<n;i++)
    {
        cin>>t;
        if(t>200000) continue;
        a[t]=1;
    }
    int kind=0;
    int i;
    for(i=1;i<=200000;i++)
    {
        if(m<i) break;
        if(a[i]==0)
        {
            m-=i;
            kind++;
        }
    }
    printf("%d\n",kind);
    for(int j=1;j<i;j++)
    {
        if(!a[j])
        printf("%d ",j);
    }
    printf("\n");
    return 0;
}
时间: 2024-12-13 09:59:45

codeforces 659C Tanya and Toys的相关文章

[2016-03-31][codeforces][659C][Tanya and Toys]

时间:2016-03-31 23:49:13 星期四 题目编号:[2016-03-31][codeforces][659C][Tanya and Toys].md 题目大意:有$10^9$种物品,第i种物品价值i,已经用用n个物品,给m元,问最多能买多少个还没拥有的物品 分析:贪心,从最低的开始买起,假设$m = 10^9$,那么也买的物品也不超过$10^6$个,因为$\frac{(1+k)k}{k} < 10^9$ 遇到的问题:答案可能为0 #include <algorithm> #

CodeForces659C Tanya and Toys map

Tanya and ToysIn Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to109. A toy from the new collection of the i-th type costs i bourles. Tania has managed to collect

Codeforces-C. Tanya and Toys(水题)

In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to109. A toy from the new collection of the i-th type costs i bourles. Tania has managed to collect n different ty

2016NEFU集训第n+3场 G - Tanya and Toys

Description In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1to 109. A toy from the new collection of the i-th type costs i bourles. Tania has managed to collect n 

CodeForces - 508D Tanya and Password(欧拉通路)

Description While dad was at work, a little girl Tanya decided to play with dad's password to his secret database. Dad's password is a string consisting of n + 2 characters. She has written all the possible n three-letter continuous substrings of the

CodeForces 518B Tanya and Postcard (题意,水题)

题意:给定两个字符串,然后从第二个中找和第一个相同的,如果大小写相同,那么就是YAY,如果大小写不同,那就是WHOOPS.YAY要尽量多,其次WHOOPS也要尽量多. 析:这个题并不难,难在读题懂题意.首先把两个字符串的的每个字符存起来,然后,先扫一遍,把所有的能YAY的都选出来,剩下的再尽量先WHOOPS. 代码如下: #include <iostream> #include <cstdio> #include <algorithm> #include <vec

codeforces 508D . Tanya and Password 欧拉通路

题目链接 给你n个长度为3的子串, 这些子串是由一个长度为n+2的串分割得来的, 求原串, 如果给出的不合法, 输出-1. 一个欧拉通路的题, 将子串的前两个字符和后两个字符看成一个点, 比如acb, 就是ac->cb. 然后建图. 1 #include <iostream> 2 #include <vector> 3 #include <cstdio> 4 #include <cstring> 5 #include <algorithm>

Codeforces 526D Tanya and Password kmp

题意:给你一个字符串 ,问你前对于任意一个前缀能不能组成  A+B+A+B...+B+A 这种形式. 解题思路:在next数组上面乱搞,判断前缀是否循环 ,循环是否为K还是K+1,为K的时候往后DP看最多能符合条件的前缀串. 解题代码: 1 // File Name: d.cpp 2 // Author: darkdream 3 // Created Time: 2015年04月06日 星期一 15时36分38秒 4 5 #include<vector> 6 #include<list&

Codeforces 508D Tanya and Password

题意: n(10^5)个串每个串3个字符  两个串abc.xyz能拼在一起前提是b=x&&c=y  它们能拼成ab(x)c(y)z  求n个串品在一起的串 思路: 将串abc变成ab->bc的一条边  则原题变成了有向图的欧拉路径问题 有向图欧拉路径算法就是遍历  因为欧拉路径其实就是"每条边走一遍" 代码: #include<cstdio> #include<iostream> #include<cstring> #inclu