ZOJ3983+3992+3993

来源:互联网 发布:grub2命令行启动linux 编辑:程序博客网 时间:2024/06/08 18:43
Crusaders Quest

Time Limit: 1 Second      Memory Limit: 65536 KB

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

7gggaaaoooaaoogggoagooggaaaoagogaooaggoooggaaagogogoaaagaogaogao

Sample Output

3321321

Hint

For the first sample test case, DreamGrid can first eliminate "aaa" (one super skill triggered), thus changing the skill blocks to "gggooo". He can then eliminate "ggg" (another super skill triggered) and finally eliminate "ooo" (a third super skill triggered). So the answer is 3.

For the second sample test case, DreamGrid can first eliminate "ggg" (one super skill triggered), thus changing the skill blocks to "aaoooa". He can then eliminate "ooo" (another super skill triggered) and finally eliminate "aaa" (a third super skill triggered). So the answer is also 3.

For the third sample test case, DreamGrid can first eliminate "aaa" (one super skill triggered), thus changing the skill blocks to "googgo". He can then eliminate "oo" to obtain "gggo", and eliminate "ggg" (another super skill triggered) to obtain "o". So the answer is 2. It is easy to prove that he cannot trigger the super skill three times under this arrangement of skill blocks.

题意:给出一个字符串,每次可以消去一个两个或者三个相同的连续的字母,问你到最后消去三个连续字母最多有几个

思路:有点贪心的意思,不过只有第一步用到了,一般思维肯定是先把三个连续的全部剔除,然后解决剩下的

在剔除三个的时候,有三种可能

①:全部剔除,如样例1,2      ②:剔除一组,剩下六个字母,如样例3   这种情况很好解决,在剩下的六个子母中,已经宝山正没有三个连续的字母,所以无论怎么消除只能出一个三个连续     ③:一个都没有剔除   没有一个三个连续的  因为事先知道字母是啥,所以就好办了,把每个字母都是一边,如果到最后凑出当前字幕的ans是多少,三次,取最大值

代码又臭又长。。。很挫~~~~~~~~~~~~

#include<iostream>#include<stdio.h>#include<string.h>#include<vector>#define ll long long#define N 1000010using namespace std;char map[11];char newmap[11];int vis[11];int max(int a,int b){    return a>b?a:b;}int main(){    int t;    cin>>t;    int i,j,k;    while(t--)    {        int ans=0;        int temp[30];         memset(temp,0,sizeof(temp));            temp[0]='A';        memset(vis,0,sizeof(vis));        for(i=1;i<=9;i++)           {            cin>>map[i];            //temp[map[i]-96]++;           }             //for(i=1;i<=26;i++)            //cout<<temp[i]<<endl;            //for(i=1;i<=9;i++)               // cout<<map[i];        for(i=1;i<=9;i++)        {            if(vis[i]!=1)            {                for(j=i+1;j<=8;j++)                    if(vis[j]!=1)                    break;                //cout<<j<<endl;                for(k=j+1;k<=9;k++)                    if(vis[k]!=1)                    break;               // cout<<k<<endl;                if(map[i]==map[j]&&map[i]==map[k])                    {                        ans++;                        vis[i]=vis[j]=vis[k]=1;                        i=1;                    }            }        }        if(ans==2)        ans++;        else if(ans==1)        {            /*k=0;            for(i=1;i<=9;i++)                if(vis[i]!=1)                newmap[k++]=map[i];*/            ans++;        }        else if(ans==0)        {            int flag=0;            memset(temp,0,sizeof(temp));            char te='a';            for(i=1;i<=9;i++)            {                if(te==map[i])                    break;            }            for(j=9;j>=1;j--)                if(te==map[j])                break;            for(k=i+1;k<j;k++)                temp[map[k]-96]++;            //cout<<temp[7]<<" "<<temp[15]<<endl;            if(temp[7]!=0&&temp[15]!=0)                ans=max(1,ans);            else ans=max(2,ans);            memset(temp,0,sizeof(temp));            te='g';            for(i=1;i<=9;i++)            {                if(te==map[i])                    break;            }            for(j=9;j>=1;j--)                if(te==map[j])                break;            for(k=i+1;k<j;k++)                temp[map[k]-96]++;            if(temp[1]!=0&&temp[15]!=0)                ans=max(1,ans);            else ans=max(2,ans);            memset(temp,0,sizeof(temp));            te='o';            for(i=1;i<=9;i++)            {                if(te==map[i])                    break;            }            for(j=9;j>=1;j--)                if(te==map[j])                break;            for(k=i+1;k<j;k++)                temp[map[k]-96]++;            if(temp[7]!=0&&temp[1]!=0)                ans=max(1,ans);            else ans=max(2,ans);        }        cout<<ans<<endl;    }    return 0;}

Safest Buildings

Time Limit: 1 Second      Memory Limit: 65536 KB

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

23 10 53 43 53 63 10 4-7 -64 55 4

Sample Output

1122 3
题意:这题很强,我喜欢,吃鸡,n个房子,给出最开始的安全区域半径,圆心是(0,0),再给出下一次安全区的半径,圆心随机,给出房子坐标,问你哪个房子会使天命圈,输出编号

思路:可以可以,我喜欢,做完这题,我基本就知道玩了好几十把吃鸡为什么没有吃过鸡的原因了~~~天命圈不在我这里,一般我就是在安全区周边做一只伏地魔,天命圈总是不找我,没办法QAQ

刚拿过这个提来,啥也没想,直接就写了个距离圆心最近肯定是最大几率的天命圈,wa

后来晓得还有必是安全区的区域啊,以毒圈的边与新安全区的圈相切,比如R=10,r=6  不管小圆圆心在哪里,圆心周围一部分区域必是安全区

即2*r-R>=l,l是距离圆心的距离

#include<iostream>#include<stdio.h>#include<string.h>#include<cmath>#include<algorithm>#include<vector>#define ll long long#define N 1000010using namespace std;int min(int a,int b){    return a<b?a:b;}int ans[N];struct node{    int id;    int l;    int x,y;}map[N];int cmp(node A,node B){    return A.l<B.l;}int main(){    int t;    int n,R,r;    cin>>t;    while(t--)    {        memset(map,0,sizeof(map));        int temp=0x3f3f3f3f;        cin>>n>>R>>r;        int d=R-2*r;        d*=d;        int num=0;       for(int i=1;i<=n;i++)        {            scanf("%d%d",&map[i].x,&map[i].y);            map[i].id=i;            map[i].l=map[i].x*map[i].x+map[i].y*map[i].y;            temp=min(temp,map[i].l);            if(map[i].l<=d)                ans[num++]=map[i].id;        }        if(num==0)        {            for(int i=1;i<=n;i++)                if(map[i].l==temp)                ans[num++]=map[i].id;        }        cout<<num<<endl;        cout<<ans[0];        for(int i=1;i<num;i++)            cout<<" "<<ans[i];            cout<<endl;        //sort(map+1,map+n+1,cmp);        //for(int i=1;i<=n;i++)            //cout<<map[i].id<<" "<<map[i].l<<endl;        //cout<<temp<<endl;    }    return 0;}



One-Dimensional Maze

Time Limit: 1 Second      Memory Limit: 65536 KB

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

33 2LRL10 4RRRRRRRLLR7 4RLLRLLR

Sample Output

021

Hint

For the first sample test case, BaoBao doesn't have to change any character and can escape from the 3rd grid. So the answer is 0.

For the second sample test case, BaoBao can change  to 'R' and  to 'R' and escape from the 10th grid. So the answer is 2.

For the third sample test case, BaoBao can change  to 'L' and escape from the 1st grid. So the answer is 1.

题意:一条线,可以向左向右移动,给你长度,和每个点的方向,问你改动几次才能走到这条线的尽头

思路:模拟一条大路走到死

#include<iostream>#include<stdio.h>#include<string.h>#include<vector>#define ll long long#define N 1000010using namespace std;char map[N];int min(int a,int b){    return a<b?a:b;}int main(){    int n,m;    int t;    cin>>t;    while(t--)    {        cin>>n>>m;        for(int i=1;i<=n;i++)            cin>>map[i];       // for(int i=1;i<=n;i++)            //cout<<map[i];        int ans1=0,ans2=0;        for(int i=m;i<n;i++)        {            if(map[i]=='L')                ans1++;        }        for(int i=m;i>1;i--)        {            if(map[i]=='R')                ans2++;        }        int ans=min(ans1,ans2);        cout<<ans<<endl;    }    return 0;}



One-Dimensional Maze

Time Limit: 1 Second      Memory Limit: 65536 KB

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

33 2LRL10 4RRRRRRRLLR7 4RLLRLLR

Sample Output

021

Hint

For the first sample test case, BaoBao doesn't have to change any character and can escape from the 3rd grid. So the answer is 0.

For the second sample test case, BaoBao can change  to 'R' and  to 'R' and escape from the 10th grid. So the answer is 2.

For the third sample test case, BaoBao can change  to 'L' and escape from the 1st grid. So the answer is 1.

原创粉丝点击