首页 > 代码库 > codeforces #381 div2

codeforces #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;}

codeforces #381 div2