训练集---训练赛14

Compote

Nikolay has a lemons, b apples and c pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1: 2: 4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can’t crumble up, break up or cut these fruits into pieces. These fruits — lemons, apples and pears — should be put in the compote as whole fruits.

Your task is to determine the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. It is possible that Nikolay can’t use any fruits, in this case print 0.
一如既往开门见水(不过话说我们这边还真有某大佬第一题用暴枚举做的真是666)

#include<bits/stdc++.h>
#define N 100001
#define ii pair<int,int>
using namespace std;
int main()
{int a,b,c;
cin>>a>>b>>c;
cout<<min(a,min(b/2,c/4))*7;    
}

Decoding

Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word’s length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, info. If the word consists of single letter, then according to above definition this letter is the median letter.

Polycarp encodes each word in the following way: he writes down the median letter of the word, then deletes it and repeats the process until there are no letters left. For example, he encodes the word volga as logva.

You are given an encoding s of some word, your task is to decode it.
也算水吧,给一个字符串让你转化成中间开始左一个右一个的字符串.

#include<bits/stdc++.h>
#define N 100001
#define ii pair<int,int>
using namespace std;
int main()
{int n,i,p,a=1,b=1;char c,ans[2010]={0};bool flag=0;
  cin>>n;
  if(n&1)p=(n+1)/2,flag=1;
  else p=n/2;
for(i=1;i<=n;i++)
  {cin>>c;
   if(i==1)ans[p]=c;
   else if(i%2==1&&flag==1)ans[p+a]=c,a++;
   else if(i%2==0&&flag==1)ans[p-b]=c,b++;
   else if(i%2==0&&flag==0)ans[p+a]=c,a++;
   else if(i%2==1&&flag==0)ans[p-b]=c,b++;
  }
 for(i=1;i<=n;i++)
 printf("%c",ans[i]);
}

Tram

The tram in Berland goes along a straight line from the point 0 to the point s and back, passing 1 meter per t1 seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points x = 0 and x = s.

Igor is at the point x1. He should reach the point x2. Igor passes 1 meter per t2 seconds.

Your task is to determine the minimum time Igor needs to get from the point x1 to the point x2, if it is known where the tram is and in what direction it goes at the moment Igor comes to the point x1.

Igor can enter the tram unlimited number of times at any moment when his and the tram’s positions coincide. It is not obligatory that points in which Igor enter and exit the tram are integers. Assume that any boarding and unboarding happens instantly. Igor can move arbitrary along the line (but not faster than 1 meter per t2 seconds). He can also stand at some point for some time.
算一道思维题吧,刚开始我又讨论人又讨论车弄得大脑缺氧发晕还是wa了,后来仔细一思考,发现最终到达终点的肯定要么是车要么是人,因此分别计算取较小的就可以了.(不过听说这道题因为数据辣鸡的可以暴力枚举每一分钟或者每一步都能过…)

#include<bits/stdc++.h>
#define N 100001
#define ii pair<int,int>
using namespace std;
int s,x1,x2,t1,t2,p,d,t,tt,road;bool flag1=0,flag2=0;
int main()
{
cin>>s>>x1>>x2>>t1>>t2>>p>>d;
if(x1>x2)flag1=1;
if(d==-1)flag2=1;
t=abs(x2-x1)*t2;
road=abs(x2-x1);
//cout<<flag1<<" "<<flag2<<endl;
if(t2<=t1)
  {cout<<t;return 0;}
if(flag1==flag2)
  {if(flag1==0)
     {if(p<=x1)
      tt=(x2-p)*t1;
     else 
      tt=(2*s+(x2-p))*t1;
     }
   else if(flag1==1)
     {if(p>=x1)
       tt=(p-x2)*t1;
      else
      tt=(2*s+(p-x2))*t1; 
     }   
  }
else if(flag1!=flag2)
   {if(flag1==0)
      {tt=(2*p+(x2-p))*t1;
      }
    else 
      {tt=(2*(s-p)+(p-x2))*t1;
        }  
   } 
   cout<<min(tt,t); 
}   

Green and Black Tea

Innokentiy likes tea very much and today he wants to drink exactly n cups of tea. He would be happy to drink more but he had exactly n tea bags, a of them are green and b are black.

Innokentiy doesn’t like to drink the same tea (green or black) more than k times in a row. Your task is to determine the order of brewing tea bags so that Innokentiy will be able to drink n cups of tea, without drinking the same tea more than k times in a row, or to inform that it is impossible. Each tea bag has to be used exactly once.
一道不错的..水题.给n杯茶,a杯绿茶,b杯红茶(话说那个第一题暴枚的大佬说这玩意叫黑茶我tm也是震惊了),再给个k,不能连续喝k杯以上的相同茶,打印种喝的方案,不行则-1.
先一直输出1个少的和多的k个的直到红绿相同,再一红一绿/一绿一红就可以了.
这里特特特特特特别要注意数据虽然小但一定要开long long,因为计算可不可以时数据要相乘,如果不开会炸int,我比赛时就因为这个在50点wa了三次…

#include<bits/stdc++.h>
using namespace std;
int main() {
    long long int  i,n,k,a,b,sum;
//freopen("in.txt","r",stdin);
    cin>>n>>k>>a>>b;
    sum=n;
    if((a+1)*k<b||(b+1)*k<a||a+b!=n||n==0) {
        cout<<"NO"<<endl;
        return 0;
    }
    if(a>b) {
        int m=a-b;
        while(m>0) {
            int cnt=0;
            for(i=1; i<=k&&i<=m; i++) {
                cout<<"G";
                cnt++;
            }
            if(i==m+1) {
                sum-=cnt;
                break;
            }
            cout<<"B";
            m-=cnt-1;
            sum-=cnt+1;
        }
        for(i=1; i<=sum; i++)
            {if(i&1)cout<<"B";
             else cout<<"G";
            }       
          } 
      else if(a<=b) {
        int m=b-a;
        while(m>0) {
            int cnt=0;
            for(i=1; i<=k&&i<=m; i++) {
                cout<<"B";
                cnt++;
            }
            if(i==m+1) {
                sum-=cnt;
                break;
            }
            cout<<"G";
            m-=cnt-1;
            sum-=cnt+1;
        }
        for(i=1; i<=sum; i++)
            {if(i&1)cout<<"G";
            else cout<<"B";
            }
    }
    cout<<endl;
}

Numbers Exchange

Eugeny has n cards, each of them has exactly one integer written on it. Eugeny wants to exchange some cards with Nikolay so that the number of even integers on his cards would equal the number of odd integers, and that all these numbers would be distinct.

Nikolay has m cards, distinct numbers from 1 to m are written on them, one per card. It means that Nikolay has exactly one card with number 1, exactly one card with number 2 and so on.

A single exchange is a process in which Eugeny gives one card to Nikolay and takes another one from those Nikolay has. Your task is to find the minimum number of card exchanges and determine which cards Eugeny should exchange.
不错的题目,给个n长度数字序列,再给1~m个可替换(每个只能用一次)的数字,让你把序列换成奇数偶数相同,问所需最小换的次数,以及换后序列.比赛时来不及做了被上一题坑爹的long long 拖久了.后来看了下发现有点难搞,百度学了map后水出来了,这里先贴代码再说思路吧.

#include<bits/stdc++.h>
#define N 200001
#define ii pair<int,int>
using namespace std;
int n,m,a[N],db=0,one=0,ans=0,i;map<int,int>mm;int yu=0,maxn,minx,cnt=1;
int main() {
    int n,m,a[N],i;
    cin>>n>>m;
    for(i=1;i<=n;i++)
     {scanf("%d",&a[i]);
      if(mm[a[i]]==1)//怼重复
       {a[i]=0;continue;
       }
      mm[a[i]]=1;
      if(a[i]&1)one++;
      else db++;
     }
    if(db<one)yu=1,maxn=one,minx=db;
    else maxn=db,minx=one,yu=0;
        while(maxn>n/2)//怼比一半多的
         {if(a[cnt]%2==yu)a[cnt]=0,maxn--;cnt++;
         }
    int gai=1;//开改
    for(i=1;i<=n;i++)
    if(a[i]==0){
        for(;gai<=m&&mm[gai]==1||!((gai%2==yu&&maxn<n/2)||(gai%2!=yu&&minx<n/2));gai++);
          if(gai<=m)
          {mm[gai]=1;a[i]=gai;
           if(gai%2==yu)
            maxn++;
           else minx++;
            ans++;
          }
    }
    if(minx+maxn<n)
      {cout<<-1;return 0;
      }
    cout<<ans<<endl;
    for(i=1;i<=n;i++)
     printf("%d ",a[i]);    
    }

简单说就是把重复的怼成0,其它标记为1存入map,之后看奇偶哪个大,如果大的(已除去重复)比一半总数多,就把它多的部分也怼成0.之后扫一下能不能在1~m范围内把0全都改好就可以了.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值