教育法典第82轮(Div.2)(ABD) 2020.02.13

A

题目

You are given a string s. Each character is either 0 or 1.

You want all 1’s in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1’s form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.

You may erase some (possibly none) 0’s from the string. What is the minimum number of 0’s that you have to erase?

Input
The first line contains one integer t (1≤t≤100) — the number of test cases.

Then t lines follow, each representing a test case. Each line contains one string s (1≤|s|≤100); each character of s is either 0 or 1.

Output
Print t integers, where the i-th integer is the answer to the i-th testcase (the minimum number of 0’s that you have to erase from s).

翻译

给你一个字符串s,每个字符不是0就是1。
你想让字符串中的所有1组成一个连续的子段。例如,如果字符串是0、1、00111或01111100,则所有1组成一个连续的子段,如果字符串是0101、100001或111111111101,则不满足此条件。
您可以从字符串中删除一些(可能没有)0。你要擦掉的0的最小数目是多少?

输入
第一行包含一个整数t(1≤t≤100)——测试用例的数量。
然后是t行,每一行代表一个测试用例。每一行包含一个字符串s(1≤|s|≤100);s的每个字符不是0就是1。

输出
打印t整数,其中第i个整数是第i个测试用例的答案(必须从s中删除的最小0数)。

例子

input
3
010011
0
1111000

output
2
0
0

大意

输入一串数字,删去0,让 ’ 1 ’ 连接起来。
删除最少数的0。

思路

确定第一个 ‘ 1 ’ 和最后一个 ‘ 1 ’ 的位置,从第一个 ‘ 1 ’ 到最后一个 ‘ 1 ’ ,找出其中的 ‘ 0 ’ 。

代码

#include <iostream>
#include <string>

using namespace std;

int main()
{
    int n;
    cin >> n;

    while(n--)
    {
        char str[110]="";//字符组为空
        cin >> str;
        int l;
        l=sizeof(str);//字符组长度
        int i,j;

        int ant=0;//第一个 ‘ 1 ’ 的位置
        for(i=0; i<l; i++)
        {
            if(str[i]=='1')
            {
                ant=i;
                break;
            }
        }

        int bbb=0;//最后一个 ‘ 1 ’ 的位置
        for(i=l-1; i>=0; i--)
        {
            if(str[i]=='1')
            {
                bbb=i;
                break;
            }
        }

        int x=0;//删除 ‘ 0 ’ 的个数
        for(j=ant; j<bbb; j++)
        {
            if(str[j]=='0')
            {
                x=x+1;
            }
        }
        cout << x << endl;//输出
    }
    return 0;

}

B

题目

Your company was appointed to lay new asphalt on the highway of length n. You know that every day you can either repair one unit of the highway (lay new asphalt over one unit of the highway) or skip repairing.

Skipping the repair is necessary because of the climate. The climate in your region is periodical: there are g days when the weather is good and if you lay new asphalt these days it becomes high-quality pavement; after that, the weather during the next b days is bad, and if you lay new asphalt these days it becomes low-quality pavement; again g good days, b bad days and so on.

You can be sure that you start repairing at the start of a good season, in other words, days 1,2,…,g are good.

You don’t really care about the quality of the highway, you just want to make sure that at least half of the highway will have high-quality pavement. For example, if the n=5 then at least 3 units of the highway should have high quality; if n=4 then at least 2 units should have high quality.

What is the minimum number of days is needed to finish the repair of the whole highway?

Input
The first line contains a single integer T (1≤T≤104) — the number of test cases.

Next T lines contain test cases — one per line. Each line contains three integers n, g and b (1≤n,g,b≤109) — the length of the highway and the number of good and bad days respectively.

Output
Print T integers — one per test case. For each test case, print the minimum number of days required to repair the whole highway if at least half of it should have high quality.

翻译

你知道每天你要么修理公路的一个单元(在公路的一个单元上铺设新的沥青),要么跳过修理。
由于气候原因,不进行修复是必要的。你所在地区的气候是周期性的:有时天气很好,如果你铺设新的沥青,这些天就会变成高质量的路面;在那之后,接下来b天的天气很糟糕,如果你在这些天铺新的沥青,它就会变成低质量的路面;g是好日子,b是坏日子,等等。
你可以确定你在一个好的季节开始的时候开始修复,换句话说,第1、2、……、g天是好的。
你并不真的关心高速公路的质量,你只是想确保至少一半的高速公路有高质量的路面。例如,如果n=5,则至少3个单元的高速公路应具有高质量;如果n=4,那么至少2个单元应该具有高质量。
完成整条公路的修理至少需要多少天?

输入
第一行包含一个整数T(1≤T≤104)——测试用例的数量。
接下来的T行包含测试用例——每行一个。每一行包含三个整数n,g和b(1≤n,g,b≤109)——高速公路的长度和好日子和坏日子的数量。

输出
打印T整数——每个测试用例一个。对于每个测试用例,打印修复整个高速公路所需的最少天数,如果其中至少一半应该是高质量的。

例子

input
3
5 1 1
8 10 10
1000000 1 1000000

output
5
8
499999500000

大意

一段路,在晴天或雨天时修。
晴天时修路,是高质量的路;
雨天时修路,是低质量的路。
要求:
修完一条路时,高质量的路至少占1/2(偶数 1/2,奇数 四舍五入)
输出天数。

思路

晴天,雨天一个周期,可以用数学的思维来解决

代码(一位学长的)

#include <iostream>

using namespace std;

typedef long long ll;//宏定义

int main()
{
    std::ios::sync_with_stdio(false);//加快输入
    cin.tie(0);//取消cin与cout之间的锁定,加快执行效率

    ll n;//例子数
    cin >> n;

    while(n--)
    {
        ll l=0;//路长
        ll s=0;//晴天
        ll w=0;//雨天
        ll ant=0;//周期
        ll sum=0;//总天数
        cin >> l >> s >> w;

        ant=(l+1)/2/s;//将题目要求的高质量路修完,需要这么多周期

        if((l+1)/2%s==0)//我们并不能确定,最后一个周期时,是只修了晴天还是晴天雨天一起修了,我们取天数少的情况考虑。
                       //剩下的在最后考虑
        {
            ant=ant-1;//周期减1
            sum=sum+s;
        }
        {
            ant=ant-1;//周期减1
            sum=sum+s;
        }
        else//若有多余的
        {
            sum=sum+(l+1)/2%s;//总天数+多余的天数
        }
        sum=sum+ant*(s+w);//总天数加+周期*(晴+阴)

        if(sum<=l)//若总天数<总路程,说明修完所要求好路的时候,整条路还有剩,那剩下的路,不管是晴天还是雨天都可以修
        {
            cout << l <<endl;
        }
        else
        {
            cout << sum <<endl;
        }
    }
    return 0;
}

D

题目

You have a bag of size n. Also you have m boxes. The size of i-th box is ai, where each ai is an integer non-negative power of two.

You can divide boxes into two parts of equal size. Your goal is to fill the bag completely.

For example, if n=10 and a=[1,1,32] then you have to divide the box of size 32 into two parts of size 16, and then divide the box of size 16. So you can fill the bag with boxes of size 1, 1 and 8.

Calculate the minimum number of divisions required to fill the bag of size n.

Input
The first line contains one integer t (1≤t≤1000) — the number of test cases.

The first line of each test case contains two integers n and m (1≤n≤1018,1≤m≤105) — the size of bag and the number of boxes, respectively.

The second line of each test case contains m integers a1,a2,…,am (1≤ai≤109) — the sizes of boxes. It is guaranteed that each ai is a power of two.

It is also guaranteed that sum of all m over all test cases does not exceed 105.

Output
For each test case print one integer — the minimum number of divisions required to fill the bag of size n (or −1, if it is impossible).

翻译

你有一个尺寸为n的袋子,还有m个盒子。第i个方框的大小是ai,其中每个ai都是2的整数非负幂。
你可以把盒子分成大小相等的两部分。你的目标是把袋子装满。
例如,如果n=10, a=[1,1,32],则必须将大小为32的盒子分成大小为16的两部分,然后再将大小为16的盒子分开。所以你可以在袋子里装1号、1号和8号的箱子。
计算填满n号袋子所需的最少分区数。

输入
第一行包含一个整数t(1≤t≤1000)——测试用例的数量。
每个测试用例的第一行包含两个整数n和m(1≤n≤1018,1≤m≤105)——袋子的大小和箱子的数量。
每个测试用例的第二行包含m个整数a1,a2,…,am(1≤ai≤109)——盒子的大小。每个ai都是2的幂。
它还保证所有测试用例上所有m的总和不超过105。

输出
对于每个测试用例,打印一个整数——填满大小为n(如果不可能,则为- 1)的袋子所需的最小分区数。

例子

input
3
10 3
1 32 1
23 4
16 1 4 1
20 5
2 1 16 1 8

output
2
-1
0

大意

袋子大小为n,有m个盒子。给出每个盒子大到小。
可以将盒子分割成相等的两份。直到可以将袋子装满。
当袋子装满时,盒子分割过几次。
若袋子不能装满,则输出 -1 。

思路

看到题目,就应该能想到2的次数幂,二进制等。
此题就是转化为二进制,从低位遍历,低位不足,则从高位拆分。
其中涉及了二进制转化,位运算。
这位up主说的很详细

代码

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
ll cnt[70];

int main()
{
    int t;cin>>t;
    while(t--)
    {
      memset(cnt,0,sizeof cnt);
      ll n,m;
      cin>>n>>m;
      ll sum=0;
      for(int i=0;i<m;i++){

          int num=0,x;
          cin>>x;
          sum+=x;
          while(x) num++,x>>=1;
          cnt[num-1]++;//将每一位的x都存起来了

      }
      if(sum<n) {puts("-1");continue;}//若全部的盒子也无法将袋子装满
      else
      {
          int ans=0;
          for(int i=0;i<=63;i++)//进行判断和拆分
          {
             int x=(n>>i)&1;
             cnt[i]-=x;
             if(cnt[i]>=2) cnt[i+1]+=cnt[i]/2;
             if(cnt[i]<0) ans++,cnt[i+1]--;
          }
          cout<<ans<<endl;
      }
    }
    return 0;
}



  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个错误提示通常表示你在Maven项目中尝试使用的Spring Boot插件版本 `spring-boot-maven-plugin:2.2.1.RELEASE` 不存在或者没有添加到项目的pom.xml配置文件中。以下是可能导致这个问题的一些原因: 1. **插件未安装**:确保你已经从Maven仓库下载并安装了对应的Spring Boot Maven插件。你可以通过运行 `mvn install:install-file -DgroupId=org.springframework.boot -DartifactId=spring-boot-maven-plugin -Dversion=2.2.1.RELEASE -Dpackaging=maven-plugin -Dfile=/path/to/spring-boot-maven-plugin-2.2.1.RELEASE.jar` 来手动安装。 2. **pom.xml配置错误**:检查你的pom.xml文件中 `<plugins>` 标签内是否有正确的 `<plugin>` 元素,包括 `<groupId>`, `<artifactId>`, 和 `<version>` 是否匹配。例如: ```xml <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.2.1.RELEASE</version> <executions> <!-- 插件的配置 --> </executions> </plugin> </plugins> </build> ``` 3. **依赖冲突**:确认是否有其他插件或模块依赖了不同版本的Spring Boot插件,导致版本冲突。如果有的话,你需要调整这些依赖项,保持一致。 4. **更新版本**:如果2.2.1.RELEASE版本确实已过期,确保你在使用的是最新的兼容版本,或者根据Spring Boot的官方文档查看是否有更推荐的替代版本。 如果你遇到这个问题,建议先清理本地Maven缓存,然后检查上述方面。如果问题依然存在,提供更多的上下文信息将有助于找到解决方案。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值