zoukankan      html  css  js  c++  java
  • codeforces Round#381 div2

    第一题:

    按余数分类,1,2,3分别由哪些基数组成

    1—>[1][2+3][3+3+3]

    2—>[1+1][2][3+3]

    3—>[1+1+1][1+2][3]

    #include<iostream>
    #include<algorithm>
    #include<cstdio>
    #include<cstring>
    #include<map>
    #include<vector>
    #include<queue>
    using namespace std;
    typedef long long ll;
    const int maxn=2e5+20;
    const ll MAX=0x7fffffffffffffff;
    int main ()
    {
       ll n,a,b,c;
       ll cost=MAX;
       cin>>n>>a>>b>>c;
       if(n%4==0)
        cout<<"0"<<endl;
       else
       {
           int tmp=4-n%4;
           if(tmp==1)
           {
               cost=min(a,b+c);
               cost=min(cost,c+c+c);
           }
           if(tmp==2)
           {
               cost=min(b,a+a);
               cost=min(cost,c+c);
           }
           if(tmp==3)
           {
               cost=min(a+a+a,b+a);
               cost=min(cost,c);
           }
           cout<<cost<<endl;
       }
        return 0;
    }
    
    
    
    
    
    
    
    

    第二题:

    选出子序列和为正的项

    #include<iostream>
    #include<algorithm>
    #include<cstdio>
    #include<cstring>
    #include<map>
    #include<vector>
    #include<queue>
    using namespace std;
    typedef long long ll;
    const int maxn=2e5+20;
    const int MAX=0x7fffffff;
    int a[102];
    int b[102],c[102];
    int main ()
    {
      int n,m,l,r,ans=0;
      cin>>n>>m;
      for(int i=1;i<=n;i++)
        cin>>a[i];
      int t=0;
      while(m--)
      {
          cin>>l>>r;
          int sum=0;
          for(int i=l;i<=r;i++)
          {
              sum+=a[i];
          }
          if(sum>0)//子序列和为正
          {
              b[t]=l;
              c[t]=r;
              t++;
          }
      }
      if(t==0)
      {
          cout<<'0';
          return 0;
      }
      else
      {
           for(int i=1;i<=n;i++)
           {
               int num=0;
               for(int j=0;j<t;j++)
               {
                   if(i>=b[j]&&i<=c[j])num++;
               }
               ans+=num*a[i];
           }
    
      }
      cout<<ans<<endl;
        return 0;
    }

    第三题:

    构造法,寻找在一个区间未出现的最小整数。那么我们可以先求出   区间长度的最小值MIN

    然后构造   0 1 2 3....MIN-1   0 1 2 .....这样构造的话 区间长度大于MIN的mex肯定不小于MIN

    #include<stdio.h>
    #include<algorithm>
    #include<string.h>
    typedef __int64 ll;
    using namespace std;
    int main()
    {
    	int n,m,i,l,r,MIN=1000005;
    	int a[100005];
    	scanf("%d%d",&n,&m);
    	for(i=1;i<=m;i++)
    		{
    			scanf("%d%d",&l,&r);
    			MIN=min(r-l+1,MIN);
    		}
    	printf("%d
    ",MIN);
    	for(i=1;i<=n;i++)
    		if(i!=n)
    			printf("%d ",i%MIN);
    		else
    			printf("%d
    ",i%MIN);
    	return 0;
    }
  • 相关阅读:
    Python 学习笔记(九)Python元组和字典(二)
    Python 学习笔记(九)Python元组和字典(一)
    Java适配器模式
    Java原型模式
    Java建造者模式
    java工厂模式
    封装图片处理方法
    TP中的图片水印
    THINKphp中复杂的查询
    THINKphp中常见的Request请求类
  • 原文地址:https://www.cnblogs.com/demian/p/6096286.html
Copyright © 2011-2022 走看看