Little Tiger vs. Deep Monkey (二维线段树)

本文介绍了一场智能竞赛,小老虎与深猴进行智力对决。比赛包含多项选择题,每题分数不同,参与者需根据难度获取相应分数。小老虎的目标是确定最低得分以确保至少有P的概率不输掉比赛。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <queue>
#include <map>
#include <bitset>
using namespace std;
#define L(i) i<<1
#define R(i) i<<1|1
#define INF  0x3f3f3f3f
#define pi acos(-1.0)
#define eps 1e-3
#define mod 1000000007
#define LL long long
#define N 15

#define INF 0x3f3f3f3f
#pragma comment(linker, "/STACK:102400000,102400000")
int T;
int n,m;
double p;

const int maxn = 20000;
const int maxm = 6400100;
int idx;

int remi,remx;

struct SegNode
{
    int l,r,b,t;
    int mx,mi;
    int ch[4];
} seg[maxm];

int newNode(int l,int r,int b,int t)
{
    idx++;
    seg[idx].l=l;
    seg[idx].r=r;
    seg[idx].b=b;
    seg[idx].t=t;

    seg[idx].mi = INF;
    seg[idx].mx = -INF;
    memset(seg[idx].ch,0,sizeof(seg[idx].ch));

    return idx;
}

void update(int x,int y,int rt,int val)
{
    if(seg[rt].l == seg[rt].r && seg[rt].b == seg[rt].t)
    {
        seg[rt].mi =val;
        seg[rt].mx = val;
        return ;
    }

    int midx = (seg[rt].l +seg[rt].r)>>1;
    int midy = (seg[rt].b + seg[rt].t)>>1;

    if(x<=midx && y<=midy)
    {
        if(seg[rt].ch[0] == 0)
            seg[rt].ch[0] = newNode(seg[rt].l,midx,seg[rt].b,midy);
        update(x,y,seg[rt].ch[0],val);

    }
    else if(x>midx && y<=midy)
    {
        if(seg[rt].ch[1] ==0)
            seg[rt].ch[1] = newNode(midx+1,seg[rt].r,seg[rt].b,midy);
        update(x,y,seg[rt].ch[1],val);

    }
    else if(x<=midx && y>midy)
    {
        if(seg[rt].ch[2]==0)
            seg[rt].ch[2] = newNode(seg[rt].l,midx,midy+1,seg[rt].t);
        update(x,y,seg[rt].ch[2],val);

    }
    else if( x>midx && y>midy)
    {
        if(seg[rt].ch[3]==0)
            seg[rt].ch[3] = newNode(midx+1,seg[rt].r,midy+1,seg[rt].t);
        update(x,y,seg[rt].ch[3],val);
    }
    seg[rt].mi = INF;
    seg[rt].mx = -INF;
    for(int i=0; i<4; i++)
    {
        if(seg[rt].ch[i]!=0) seg[rt].mi = min(seg[rt].mi,seg[seg[rt].ch[i]].mi);
        if(seg[rt].ch[i]!=0) seg[rt].mx = max(seg[rt].mx,seg[seg[rt].ch[i]].mx);
    }
}

void query(int x1,int y1,int x2,int y2,int rt)
{
   // printf("%d %d %d %d\n",x1,y1,x2,y2);
    if(x1<=seg[rt].l && x2>=seg[rt].r && y1<=seg[rt].b && y2>=seg[rt].t)
    {
        remi = min(remi,seg[rt].mi);
        remx = max(remx,seg[rt].mx);
        return ;
    }

    int midx = (seg[rt].l +seg[rt].r)>>1;
    int midy = (seg[rt].b +seg[rt].t)>>1;

    if(x1<=midx && y1<=midy)
    {
        if(seg[rt].ch!=0)
        {
            query(x1,y1,x2,y2,seg[rt].ch[0]);
        }
    }
    if(x2>midx && y1<=midy)
    {
        if(seg[rt].ch[1]!=0)
        {
            query(x1,y1,x2,y2,seg[rt].ch[1]);
        }
    }

    if(x1<=midx && y2>midy)
    {
        if(seg[rt].ch[2]!=0)
        {
            query(x1,y1,x2,y2,seg[rt].ch[2]);
        }
    }

    if(x2>midx && y2>midy)
    {
        if(seg[rt].ch[3]!=0)
            query(x1,y1,x2,y2,seg[rt].ch[3]);
    }
}

int a,b,c;

int main()
{
    int cas=1;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);

        idx=0;
        newNode(1,n,1,n);

        for(int i=1; i<=n; i++)
            for(int j=1; j<=n; j++)
            {
                scanf("%d",&a);
                update(i,j,1,a);
            }

        for(int i=1; i<=n; i++)
            for(int j=1; j<=n; j++)
            {
                remi = INF;
                remx = -INF;
                query(1,1,i,j,1);
                printf("%d %d\n",remi,remx);
            }

        scanf("%d",&m);
        printf("Case #%d:\n",cas++);
        for(int i=0; i<m; i++)
        {
            scanf("%d%d%d",&a,&b,&c);

            remi = INF;
            remx = -INF;

            query(max(1,a-c/2),max(1,b-c/2),min(n,a+c/2),min(n,b+c/2),1);

            printf("%d\n",(remi+remx)/2);

            update(a,b,1,(remi + remx)/2);
        }
    }
    return 0;
}





















Description
A crowd of little animals is visiting a mysterious laboratory �C The Deep Lab of SYSU. 

“Are you surprised by the STS (speech to speech) technology of Microsoft Research and the cat face recognition project of Google and academia? Are you curious about what technology is behind those fantastic demos?” asks the director of the Deep Lab. “Deep learning, deep learning!” Little Tiger raises his hand briskly. “Yes, clever boy, that’s deep learning (深度学习/深度神经网络)”, says the director. “However, they are only ‘a piece of cake’. I won’t tell you a top secret that our lab has invented a Deep Monkey (深猴) with more advanced technology. And that guy is as smart as human!” 

“Nani ?!” Little Tiger doubts about that as he is the smartest kid in his kindergarten; even so, he is not as smart as human, “how can a monkey be smarter than me? I will challenge him.” 

To verify their research achievement, the researchers of the Deep Lab are going to host an intelligence test for Little Tiger and Deep Monkey. 

The test is composed of N binary choice questions. And different questions may have different scores according to their difficulties. One can get the corresponding score for a question if he chooses the correct answer; otherwise, he gets nothing. The overall score is counted as the sum of scores one gets from each question. The one with a larger overall score wins; tie happens when they get the same score. 

Little Tiger assumes that Deep Monkey will choose the answer randomly as he doesn’t believe the monkey is smart. Now, Little Tiger is wondering “what score should I get at least so that I will not lose in the contest with probability of at least P? ”. As little tiger is a really smart guy, he can evaluate the answer quickly. 

You, Deep Monkey, can you work it out? Show your power!�

Input

The first line of input contains a single integer T (1 ≤ T ≤ 10) indicating the number of test cases. Then T test cases follow. 

Each test case is composed of two lines. The first line has two numbers N and P separated by a blank. N is an integer, satisfying 1 ≤ N ≤ 40. P is a floating number with at most 3 digits after the decimal point, and is in the range of [0, 1]. The second line has N numbers separated by blanks, which are the scores of each question. The score of each questions is an integer and in the range of [1, 1000]�

Output

For each test case, output only a single line with the answer.

Sample Input

1
3 0.5
1 2 3

Sample Output

3



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值