11-19 秦皇岛重现赛水题总结之c,l,m

    今天是十一月二十九号啦,下午写了秦皇岛ccpc的题,然后当时是做了三题出来的,然后现在是要再补一补a和e,但是在这之前还是先总结一下下午做的三道题把。

稍后再发表a和e的思路总结

L-One-Dimensional Maze

BaoBao is trapped in a one-dimensional maze consisting of grids arranged in a row! The grids are numbered from 1 to from left to right, and the -th grid is marked with a character , where is either ‘L’ or ‘R’.

Starting from the -th grid, BaoBao will repeatedly take the following steps until he escapes the maze:

If BaoBao is in the 1st grid or the -th grid, then BaoBao is considered to arrive at the exit and thus can escape successfully.
Otherwise, let BaoBao be in the -th grid. If , BaoBao will move to the -th grid; If , Baobao will move to the -th grid.
Before taking the above steps, BaoBao can change the characters in some grids to help himself escape. Concretely speaking, for the -th grid, BaoBao can change from ‘L’ to ‘R’, or from ‘R’ to ‘L’.

But changing characters in grids is a tiring job. Your task is to help BaoBao calculate the minimum number of grids he has to change to escape the maze.

Input
There are multiple test cases. The first line of the input contains an integer , indicating the number of test cases. For each test case:

The first line contains two integers and (, ), indicating the number of grids in the maze, and the index of the starting grid.

The second line contains a string () consisting of characters ‘L’ and ‘R’. The -th character of indicates the character in the -th grid.

It is guaranteed that the sum of over all test cases will not exceed .

Output
For each test case output one line containing one integer, indicating the minimum number of grids BaoBao has to change to escape the maze.

Sample Input
3
3 2
LRL
10 4
RRRRRRRLLR
7 4
RLLRLLR
Sample Output
0
2
1

题意:这道题的题意就是说有一个一维的迷宫,上面的字符是L或者R,然后宝宝在m的初始位置,问从m开始想要走到出口(0或n-1)所需要更改字符的最小次数是多大。
思路:因为宝宝想要出去的话就只能一直往左或者一直往右,所以遍历出往左走到终点的过程中有几个R记为l,同理往右走的几个L记为r,l和r就是要修改的位置,然后取其中较小的那个即为答案了。
下面是代码:

#include <iostream>
#include <memory.h>
using namespace std;
char maze[100005];
int t,n,m;
int search(int m){
    int l=0;
    int r=0;
    for(int i=m;i>=2;i--){
        if(maze[i]!='L'){
            l++;
        }
    }
    for(int i=m;i<=n-1;i++){
        if(maze[i]!='R'){
            r++;
        }
    }
    return l<r?l:r;
}

int main(){

    cin>>t;
    while(t--){
        cin>>n>>m;
        memset(maze,0,sizeof(maze));
        for(int i=1;i<n+1;i++){
            cin>>maze[i];
        }
        cout<<search(m)<<endl;
    }
    return 0;
}

L题没什么好说的,然后是C题。


C-Crusaders Quest
Crusaders Quest is an interesting mobile game. A mysterious witch has brought great darkness to the game world, and the only hope for your kingdom is to save the Goddesses so that they can unleash their power to fight against the witch.

In order to save the game world, you need to choose three heroes to fight for victory and use their skills wisely. Nine skill blocks of three different types (three blocks per type) will be presented at the bottom of the screen. If () consecutive blocks are of the same type, you can tap on them and eliminate them, thus triggering the powerful skill they represent. After the elimination, the blocks to their left will be connected with the blocks to their right. Moreover, if consecutive blocks of the same type are eliminated, the powerful skill they unleash will be upgraded to a super skill, which is the most powerful skill of all.

DreamGrid is a newbie in this game, and he wants to trigger the super skill as many times as he can. Given nine skill blocks satisfying the description above, please help DreamGrid calculate the maximum number of times he can trigger the super skill.

Input
There are multiple test cases. The first line of input contains an integer (about 50), indicating the number of test cases. For each test case:

The first line contains a string () consisting of three ‘g’s, three ‘a’s and three ‘o’s, representing the nine skill blocks of three different types. Each type of character represents one type of skill block.

Output
For each test case, output an integer denoting the maximum number of times DreamGrid can trigger the super skill.

Sample Input
7
gggaaaooo
aaoogggoa
googgaaao
agogaooag
goooggaaa
gogogoaaa
gaogaogao
Sample Output
3
3
2
1
3
2
1

题意:有九个技能,可以每次任意消除k个(k>=1),而当且仅当k==3时称为一次超级技能,求最多能释放几次超级技能。
思路:因为只有九个技能,其中只有三种,所以就直接模拟一下放技能的过程,首先先把连在一起的三个相同的技能消除,如果消除之后还有连在一起的技能的话就继续消除,直到没有为止。在经过这种处理之后,剩下的技能有以下几种排列可能:
1.什么都没有
2.剩下九个
3.剩下六个
(是的,不可能剩下三个,因为剩下三个的话必是三个一样的技能被消除了)
所以如果有剩下技能的情况,他必定不能把三种技能全都释放成超级技能(满足答案为3的字符串必定满足有一组连续三个相同技能的条件),所以在剩下六个的情况下,必定只能再释放一次。
但是剩下九个的情况,可能是一次,也有可能是两次,接着前面的思路–必定不满足答案为3,所以最好的情况是舍弃掉其中的一种,剩下两种可以释放两次超级技能,所以对于处理后仍然为9的字符串做这样的处理,分别舍弃三个技能中的一种,然后进行释放超级技能的处理,取三种情况中释放最多的情况。

虽然做法很蠢但是也是因地制宜呀,先a为敬hhhh

#include <iostream>
#include <memory.h>
#include <string.h>
using namespace std;
string str;

void del(int k,string& str){
    for(int i=k;i<str.size()-1;i++){
        str[i]=str[i+1];
    }
    str[str.size()-1]='\0';
}



int solve(int &cnt,string& str){
    int i=0;
    while(i<str.size()){

            if(str[i]==str[i+1]&&str[i+1]==str[i+2]&&str[i]!='\0'){
                for(int k=i+2;k>=i;k--){
                    del(k,str);
                }
                cnt++;
                i=0;
                continue;
            }
            i++;
    }
}
int main(){
    int n;

    cin>>n;
    while(n--){
        cin>>str;

        int count=0;
        solve(count,str);


        if(count==3){
            cout<<"3\n";
        }else{
            int cnta,cntg,cnto;
            int maxCnt=0;
            cnta=cntg=cnto=0;

            string tempa=str;
            for(int i=tempa.size();i>=0;i--){
                if(tempa[i]=='a')
                    del(i,tempa);
            }
            solve(cnta,tempa);
            maxCnt=maxCnt>cnta?maxCnt:cnta;

            string tempg=str;
            for(int i=tempg.size();i>=0;i--){
                if(tempg[i]=='g')
                    del(i,tempg);
            }
            solve(cntg,tempg);
            maxCnt=maxCnt>cntg?maxCnt:cntg;

            string tempo=str;
            for(int i=tempo.size();i>=0;i--){
                if(tempo[i]=='o')
                    del(i,tempo);
            }
            solve(cnto,tempo);
            maxCnt=maxCnt>cnto?maxCnt:cnto;

            count+=maxCnt;
            if(count==0)
                count=1;
            cout<<count<<endl;
        }
        //cout<<str<<endl;
    }
    return 0;
}

M-Safest Buildings
PUBG is a multiplayer online battle royale video game. In the game, up to one hundred players parachute onto an island and scavenge for weapons and equipment to kill others while avoiding getting killed themselves. BaoBao is a big fan of the game, but this time he is having some trouble selecting the safest building.

There are buildings scattering on the island in the game, and we consider these buildings as points on a two-dimensional plane. At the beginning of each round, a circular safe area whose center is located at (0, 0) with radius will be spawned on the island. After some time, the safe area will shrink down towards a random circle with radius (). The whole new safe area is entirely contained in the original safe area (may be tangent to the original safe area), and the center of the new safe area is uniformly chosen within the original safe area.

The buildings covered by the new safe area is called the safe buildings. Given the radius of the safe areas and the positions of the buildings, BaoBao wants to find all the buildings with the largest probability to become safe buildings.

Input
There are multiple test cases. The first line of input contains an integer , indicating the number of test cases. For each test case:

The first line contains three integers (), and (), indicating the number of buildings and the radius of two safe circles.

The following lines each contains 2 integers and (), indicating the coordinate of the buildings. Here we assume that the center of the original safe circle is located at , and all the buildings are inside the original circle.

It’s guaranteed that the sum of over all test cases will not exceed 5000.

Output
For each test case output two lines.

The first line contains an integer , indicating the number of buildings with the highest probability to become safe buildings.

The second line contains integers separated by a space in ascending order, indicating the indices of safest buildings.

Please, DO NOT output extra spaces at the end of each line.

Sample Input
2
3 10 5
3 4
3 5
3 6
3 10 4
-7 -6
4 5
5 4
Sample Output
1
1
2
2 3

题意:吃鸡游戏里一开始有一个安全区域,是一个以0,0为圆心的半径为R的圆,然后在这个安全区域里面有n个建筑,宝宝在空降之后,安全区域会缩小成一个更小的圆,这个小圆必被大圆内含或内切,然后再缩小之后还在安全区域内的建筑称为安全建筑,宝宝想降落在最可能成为安全建筑的建筑上,请输出最有可能成为安全建筑的建筑物有几个,并输出他们的下标值。
思路:以某点为圆心,以2*r为半径画圆,可得的面积为判断安全概率大小的依据。
当R>2*r 时,
在以原点为圆心,以R-2*r为半径的圆的范围内的点的安全概率为100%;
若不存在这样的点,越靠近原点,安全概率越大;
当R<=2*r时,
在以原点为圆心,以2*r-R为半径的圆的范围内的点的安全概率为100%;
若不存在这样的点,越靠近原点,安全概率越大。

代码:

#include <iostream>
#include <stdio.h>

using namespace std;

const int N = 3e5 + 10;

int a[N];

struct node{
    double x;
    double y;
    double dist;
    int id;
}p[N]; 

int main(){
    int t;
    scanf("%d",&t);

    while(t--){
        int n,u,R,r,d,maxt;
        scanf("%d%d%d",&n,&R,&r);
        d=R-2*r;
        maxt=-1;
        int k=0;
        for(int i=1;i<=n;i++){
            int x,y;
            scanf("%d%d",&x,&y);
            int dist=x*x+y*y;
            p[i].x=x;
            p[i].y=y;
            p[i].dist=dist;
            p[i].id=i;
            if(dist<=d*d)
                a[k++]=i;
            if(maxt==-1||dist<=maxt)
                maxt=dist;
        }
        if(k==0){
            for(int i=1;i<=n;i++){
                if(p[i].dist==maxt)
                    a[k++]=i;
            }
        }
        printf("%d\n",k);
        for(int i=0;i<k;i++){
            printf("%d%c",a[i],i==k-1?'\n':' ');
        }
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值