Codeforces Round #262 (Div. 2) (460A 460B 460C 460D)

460A Vasya and Socks

题意:n个物品每天用一个  m天得一个  问  最多连续用几天

思路:

没思路…  就是暴力…

代码:

#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<vector>
using namespace std;

int main()
{
    int n,m,ans=0,i=0;
    scanf("%d%d",&n,&m);
    while(1)
    {
        if(!n) break;
        n--;
        ans++;
        i++;
        if(i==m)
        {
            n++;
            i=0;
        }
    }
    printf("%d\n",ans);
    return 0;
}

460B Little Dima and Equation

题意:给出算式 x=b*S(x)^a+c  其中S(x)表示十进制表示下x的各位数字之和  输入abc  问有几个x满足等式  输出所有x

思路:

x很大  但是S(x)很小最多9*9  又因为算式由等号连接  所以可以枚举S(x)再算x  注意  输出x前一定要排序!!

代码:

#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<vector>
using namespace std;
typedef __int64 LL;

int a,b,c,ans,f[1000000];

bool yes(LL t,int i)
{
    int tmp=0;
    while(t)
    {
        tmp+=t%10;
        t/=10;
    }
    return tmp==i;
}

int main()
{
    int i,j;
    LL res;
    scanf("%d%d%d",&a,&b,&c);
    for(i=1;i<=85;i++)
    {
        res=1;
        for(j=1;j<=a;j++) res*=i;
        res=res*b+c;
        if(res>0&&res<(int)1e9&&yes(res,i))
        {
            f[ans++]=res;
        }
    }
    sort(f,f+ans);
    printf("%d\n",ans);
    for(i=0;i<ans;i++) printf("%d%s",f[i],(i!=ans-1)?" ":"\n");
    return 0;
}

460C Present

题意:有n朵花  每天可以浇水连续w朵  浇水后花长高1  问m天后  最矮的花最高有多高

思路:

“最小值最大”想到了二分搜索答案  复杂度O(logx)  如果给出答案如何判断能不能在m天内完成呢  可以O(n)维护实际高度与二分结果的差  然后再O(n)扫一遍  如果这朵花需要浇水  那么连续浇w朵  利用一个add数组和指针k来操作  这样总的复杂度就为O(nlogx)  注意这里x最大值是1e9+1e5

代码:

#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<vector>
using namespace std;
typedef __int64 LL;
#define N 200010

int n,m,w;
int a[N],add[N],f[N];

bool yes(int x)
{
    int i,k;
    LL need=0;
    for(i=1;i<=n;i++)
    {
        add[i]=0;
        if(a[i]<x) f[i]=x-a[i];
        else f[i]=0;
    }
    for(i=1,k=0;i<=n;i++)
    {
        k+=add[i];
        if(k<f[i])
        {
            need+=f[i]-k;
            add[i+w]+=k-f[i];
            k=f[i];
        }
    }
    return need<=m;
}

int main()
{
    int i,l=1,r=(int)1e9+(int)1e6,mid,ans;
    scanf("%d%d%d",&n,&m,&w);
    for(i=1;i<=n;i++) scanf("%d",&a[i]);
    while(l<=r)
    {
        mid=(l+r)>>1;
        if(yes(mid))
        {
            ans=mid;
            l=mid+1;
        }
        else r=mid-1;
    }
    printf("%d\n",ans);
    return 0;
}

460D Little Victor and Set

题意:构造一个集合  使得集合中不超过k个元素  且每个元素在[L,R]区间内  问该集合所有元素异或和最小是多少并输出一种方案

思路:

一道不错的想法题  一开始只能想到先分类讨论试试

首先只有一个元素  那么异或和就是L  方案也就一个L

接着有两个元素  那么如果是 2x , 2x+1  则异或和为1  方案是连个元素  如果是 2x+1 , 2x  则需要讨论L和L^R谁小

然后有三个元素  一定能构造出异或和为1  尝试构造异或和为0

如果最小的元素是x  那么可以构造出最大的元素y  即如果x的二进制是11001  则y是110000  方法为保留x的最大的1并在前面再填一个1(为什么这样? 因为这两个1就能保证x是三者中最大的)  这时x和y的异或就是中间的元素  那么如果我用L当x  则y如果<=R  就可以有一个解(为什么用L当x  因为这样的y最小)

最后有四个元素  如果刚才的方法构造不出0  还可以这样构造  按照两个元素的方法构造2个1  这样也是0

代码:

#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<vector>
using namespace std;
typedef __int64 LL;

LL l,r,k;

int main()
{
    scanf("%I64d%I64d%I64d",&l,&r,&k);
    if(k>=4)
    {
        if(l&1)
        {
            if(l+4<=r)
            {
                printf("0\n4\n%I64d %I64d %I64d %I64d\n",l+1,l+2,l+3,l+4);
                return 0;
            }
        }
        else
        {
            if(l+3<=r)
            {
                printf("0\n4\n%I64d %I64d %I64d %I64d\n",l+1,l+2,l+3,l);
                return 0;
            }
        }
    }
    if(k>=3)
    {
        LL f,t=l;
        int num=0;
        while(t)
        {
            num++;
            t>>=1;
        }
        f=(1LL<<num)|(1LL<<(num-1));
        if(f<=r)
        {
            printf("0\n3\n%I64d %I64d %I64d\n",f,l,f^l);
            return 0;
        }
    }
    if(k>=2)
    {
        if(l&1)
        {
            if(l+2<=r)
            {
                printf("1\n2\n%I64d %I64d\n",l+1,l+2);
                return 0;
            }
        }
        else
        {
            if(l+1<=r)
            {
                printf("1\n2\n%I64d %I64d\n",l,l+1);
                return 0;
            }
        }
        if((l^r)<l)
        {
            printf("%I64d\n2\n%I64d %I64d\n",l^r,l,r);
            return 0;
        }
    }
    printf("%I64d\n1\n%I64d\n",l,l);
    return 0;
}
时间: 2024-08-01 20:01:37

Codeforces Round #262 (Div. 2) (460A 460B 460C 460D)的相关文章

Codeforces Round #262 (Div. 2)460A. Vasya and Socks(简单数学题)

题目链接:http://codeforces.com/contest/460/problem/A A. Vasya and Socks time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya has n pairs of socks. In the morning of each day Vasya has to put o

Codeforces Round #262 (Div. 2) 460B. Little Dima and Equation(枚举)

题目链接:http://codeforces.com/problemset/problem/460/B B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Dima misbehaved during a math lesson a lot and the nas

Codeforces Round #262 (Div. 2) 460C. Present(二分)

题目链接:http://codeforces.com/problemset/problem/460/C C. Present time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little beaver is a beginner programmer, so informatics is his favorite subjec

Codeforces Round #262 (Div. 2) 总结:二分

B. Little Dima and Equation 思路:本来前两题都很快做出来的,然后觉得ranting应该可以增加了.然后觉得代码没问题了,又想到了一组cha人的数据,然后就锁了,然后刚锁就被别人cha了看了代码才发现尼玛忘了判断小于10^9了,然后C反正想了好多种方法都不会就没心情了,就这样rating又降了 #pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream> #in

Codeforces Round #262 (Div. 2)

Codeforces Round #262 (Div. 2) A:水题,直接不断模拟即可 B:由于s(x)大小最大到1e9,所以数位和最多为81,这样只要枚举s(x),就只要枚举1到81即可,然后在计算出x,判断是否符合,符合就加进答案 C:二分高度,然后判断的时候for一遍,每次不符合的位置就去浇水,从左往右推一遍即可 D:构造,如果k >= 5, 那么就可以直接放偶数,奇数,偶数,奇数,由于偶数和偶数+1异或必然为1,所以这样放4个异或和就到最小的0了,然后k = 1,2,4都可以特判到,关

Codeforces Round #262 (Div. 2) 题解

A. Vasya and Socks time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When

Codeforces Round #262 (Div. 2) B

题目: B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following pr

Codeforces Round #262 (Div. 2) C

题目: C. Present time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his informatics teacher is going to have

Codeforces Round #262 (Div. 2)解题报告

详见:http://robotcator.logdown.com/posts/221514-codeforces-round-262-div-2 1:A. Vasya and Socks   http://codeforces.com/contest/460/problem/A 有n双袜子,每天穿一双然后扔掉,每隔m天买一双新袜子,问最多少天后没有袜子穿.. 简单思维题:以前不注重这方面的训练,结果做了比较久,这种题自己边模拟边想.不过要多考虑trick ```c++ int main(){ i