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



### 回答1: rtos文件系统是嵌入式系统中常用的文件系统,可以提供可靠的数据存储和管理功能。在rtos文件系统中,littlefs和spiffs是两个常见的选择。 首先,littlefs是一个轻量级的文件系统,专为资源有限的系统设计。它采用了一种日志结构的文件系统布局,能够快速进行读写操作,并且占用较小的存储空间。littlefs具有良好的可靠性和数据一致性,支持事务操作和崩溃恢复。它还提供了高效的垃圾收集机制,能够自动回收闲置的存储空间。 与之相比,spiffs是一个适用于闪存的文件系统。它使用了SPI Flash索引文件系统的设计,能够有效地管理存储在闪存中的文件。spiffs具有较低的存储开销,支持节省内存的文件缓存机制,同时还提供了数据压缩和加密的选项。spiffs还可以进行动态大小可调整的磁盘分区,能够根据需要调整文件系统大小。 在性能方面,littlefs更注重对于速度和空间的折中。它的读写速度较快,且具有较小的内存占用。而spiffs则更注重对于闪存的优化,能够提供更好的存储效率和数据可靠性。 总结而言,选择哪种rtos文件系统取决于具体的应用需求。如果资源有限且对于快速读写操作和小存储空间要求较高,可以选择littlefs。如果需要管理闪存文件并且对于存储效率和数据可靠性较为重要,可以选择spiffs。无论选择哪种文件系统,都需要根据具体的应用场景进行评估和测试,以获得最佳的性能和可靠性。 ### 回答2: LittleFS和SPIFFS都是实时操作系统(RTOS)中的文件系统,用于在嵌入式系统中管理存储和访问文件。 LittleFS是一个基于嵌入式设备的轻量级文件系统,具有较小的存储和处理要求。它专为闪存设备而设计,提供了快速的启动时间和低内存占用。LittleFS使用树状或平面结构组织文件和目录,支持文件的快速查找和读取。它还具有事务性写入,这意味着它可以保证文件系统的完整性,即使在意外断电的情况下也能保持数据的一致性。由于LittleFS专为嵌入式设备而优化,因此它适用于资源受限的环境,并提供良好的性能和可靠性。 SPIFFS也是一个针对嵌入式设备的文件系统,但相对于LittleFS,它更适用于较小容量的闪存设备。SPIFFS使用固定大小的块来组织存储,并使用哈希表维护文件的索引。SPIFFS具有较低的内存占用和灵活的文件管理,但启动时间较长,并且不支持事务性写入。SPIFFS适用于对存储容量要求不高的应用,例如传感器数据日志和配置文件存储。 LittleFS和SPIFFS的选择取决于嵌入式设备的要求。如果设备有更多的存储空间,并希望获得更好的性能和可靠性,可以选择LittleFS。如果设备的存储需求较小,但需要较低的内存占用和灵活的文件管理,可以选择SPIFFS。总的来说,这两个文件系统都可以在嵌入式系统中有效地管理和访问文件。 ### 回答3: RTOS文件系统是嵌入式系统中用于管理存储设备的文件系统。在RTOS领域,LittleFS和SPIFFS是两个常见的文件系统,下面将对它们进行对比。 首先,它们都是为嵌入式系统设计的轻量级文件系统,具有较小的存储器占用和快速的读写性能。它们都支持块和扇区级的存储设备,并使用自定义的格式来组织文件和目录。 然而,LittleFS在某些方面与SPIFFS有所不同。首先,LittleFS采用了一种日志结构的设计,它将文件操作以日志的形式记录下来,从而提供了更可靠的数据一致性,并减少了文件系统损坏的风险。相比之下,SPIFFS使用了类似于FAT文件系统的索引结构,可能会导致数据损坏或文件系统恢复的困难。 其次,LittleFS具有更高的性能。它采用了一种较新的索引算法,可以快速定位和访问文件,从而提供更好的读取和写入性能。而SPIFFS在大文件和大量文件情况下,性能可能会下降。 最后,LittleFS的API设计更简单直观,易于使用和集成到项目中。而SPIFFS的API相对比较复杂,需要更多的学习成本和开发时间。 综上所述,LittleFS和SPIFFS都是在嵌入式系统中常用的RTOS文件系统。LittleFS具有更好的数据一致性、更高的性能和更简单的API设计,适用于对数据完整性有较高要求的应用场景。而SPIFFS适用于对性能和存储占用要求不高的普通应用场景。选择适合自己需求的文件系统能够提高系统的稳定性和性能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值