码迷,mamicode.com
首页 > 其他好文 > 详细

codeforces #381 div2

时间:2016-11-24 09:28:29      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:style   div   space   names   inline   tables   ios   ons   ffffff   

第一题:

按余数分类,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;
}

codeforces #381 div2

标签:style   div   space   names   inline   tables   ios   ons   ffffff   

原文地址:http://www.cnblogs.com/demian/p/6096286.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!