JZOJ5679. 【GDOI2018Day2模拟4.21】山景城

44 篇文章 0 订阅
6 篇文章 0 订阅

题目描述

Description
山景城毗邻雷克雅未克,位于美国东南部,高楼林立,彻夜灯明,是美国乃至世界的经济贸易中心。最有名的地标建筑当属南岸花园广场,这里不仅是洛杉矶银河队的主场,并且众多国际歌星,如二人转演员蕾哈娜,伟大的人民艺术家 pdd 都曾在这里举办过演唱会。
花园广场球馆的内部由 n 个独立的展厅组成,不同展厅间由 n − 1 条双向的走廊连接而互相可达。二月三十一号那天,花园广场球馆将会对公众开放展览文艺复兴时期的代表作品《蒙娜丽莎的假笑》,怪盗基德闻声披着夜色降临于此。不过 Kris 透过馆内高端的红外线监控设施,很快便发现了基德,怪盗基德降临在 s 号展厅,而 Kris 此刻所在的监控室位于展厅 t,Kris 想引诱基德至展厅 t 以瓮中捉鳖。
从基德进入南岸花园广场球馆后的那一刻开始,双方便开始了斗智斗勇,在第 i 秒钟:
• Kris 在这一秒的开始,可以进行决策:1) 不操作;2) 炸毁一条还存在的走廊,操作过后这条走廊将不复存在;3) 清除一条走廊上被怪盗基德留下标记。
• 怪盗基德在这一秒的末尾,有可能会移动:假设基德此刻正处于 p 号展厅,若从 p 号展厅出发通往相邻展厅的每条走廊都被画上了标记,那么基德会原地不动;否则,基德会从 p 出发的未被标记的走廊中选择一个,走到对应的展厅,并在这条走廊上留下标记(若存在从 p 出发的未被标记的走廊,基德必须移动,不能选择原地停留)。
(注意:以上过程中 Kris 先决策,决策完了之后基德再会行动)
在这一秒的博弈结束后,若怪盗进入了 t 号展厅,博弈停止,否则进入下一秒的博弈。
Kris 炸毁走廊与清除标记都算作一次操作。Kris 希望用尽量少的操作次数抓住基德;而基德希望Kris 用尽量多的操作才能抓住他,并在 Kris 眼皮底下逃之夭夭,以羞辱他。
由于怪盗基德过于神仙,而 Kris 具有上帝视角,双方都十分清楚对方的心思,知道双方的位置,并熟知花园广场球馆的地图。此次是怪盗基德第一次造访花园广场球馆,所以所有的走廊在博弈开始前都没有任何标记。双方都会采取最优决策,请求出 Kris 操作的次数。

Input
第一行,三个整数 n,t,s。
接下来 n−1 行,每行两个整数 ui ,vi ,描述一条连接 ui 与 vi 的通道。
Output
一行,表示答案。

Sample Input
10 1 4
1 2
2 3
2 4
3 9
3 5
4 7
4 6
6 8
7 10
Sample Output
4

Data Constraint
subtask1 20pts,n ≤ 10。
subtask2 20pts,保证存在一条 s 到 t 的走廊。
subtask3 20pts,n ≤ 1000。
subtask4 40pts,没有额外限制。 对于100%的数据,1≤t,s,n≤10^6 。

奇妙的题面

20%

不会
博弈类的题目暴力一般都比正解难写

40%(20%+暴力)

因为给出的是一颗树,而s和t之间又有边
所以一定是这样一个图

这里写图片描述

即以t为根时,s不可能走到s的其它兄♂弟节点
这里写图片描述

于是设w[i]表示
最优决策下,基德从i的叶子走到i再走到t的操作数(Kris)

所以上面的图的w是这样的
这里写图片描述

讲一下w[i]的求法
①i是叶子节点
那么可以直接一路推(从t开始),求出所有相关的边

②i不是叶子节点
因为Kris不希望基德的步数多,所以Kris在基德走到i时一定会清除掉连向最大的节点的边
但是由于Kris每次只能清除一条边,所以对于次大的节点就无能为力了。

因此基德每次都会走向次大节点(如果只有一个那么就直接被困住)

一些疑惑

至于为什么Kris只删同层的边,而不是删更下的边?

举个栗子:
这里写图片描述

还是刚刚那幅图,比如一开始可以这样删:
这里写图片描述

但是根据w的式子来看,删掉下面的点并不会使答案更优。
就算删掉的是影响该点的值,那这样不如直接把整棵树删掉。

100%

没有了20%的限制(s可以直接到t),所以s到t之间可能会有其它点
这里写图片描述
而Kris无法把这些路径上的边删掉,因为删掉了基德就走不到t

还是按照40%定义w
因为无法直接求,所以考虑二分答案。

设其为ans
那么沿着s到t的路径,如果有一个点的子节点的w大于ans,那么这个边肯定要删,如果不删就会比答案大
每次考虑一个点,中途再判断一下不成立的情况:
①删掉的边(设其为cut)>当前可删次数(就是基德一路走来的步数)
②cut>ans

还有记得打人工栈

code

#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define min(x,y) (x<y?x:y)
#define max(x,y) (x>y?x:y)
using namespace std;

int a[2000001][2];
int ls[1000001];
int f[1000001];
int d[1000001];
int num[1000001];
int i,j,k,n,S,T,len,m,Find,N,l,r,mid;
bool Bz[1000001];
int D[1000001][2];
bool bz;

int p[1000001][6];
bool b[1000001];
int Len;

void New(int x,int y)
{
    len++;

    a[len][0]=y;
    a[len][1]=ls[x];
    ls[x]=len;

    num[x]++;
}

void init()
{
    memset(b,0,sizeof(b));

    Len=1;
    p[1][0]=T;
    p[1][1]=0;
    p[1][2]=0;
    p[1][3]=0;
    p[1][4]=0;
    p[1][5]=ls[T];

    while (Len)
    {
        for (; p[Len][5] && a[p[Len][5]][0]==p[Len][1]; p[Len][5]=a[p[Len][5]][1]);

        if (p[Len][5] && !b[a[p[Len][5]][0]])
        {
            Len++;
            p[Len][0]=a[p[Len-1][5]][0];
            p[Len][1]=p[Len-1][0];
            p[Len][2]=p[Len-1][2]+num[a[p[Len-1][5]][0]]-1-Bz[a[p[Len-1][5]][0]]+(a[p[Len-1][5]][0]==S);
            p[Len][3]=0;
            p[Len][4]=0;
            p[Len][5]=ls[a[p[Len-1][5]][0]];
        }

        for (; Len && !p[Len][5]; Len--)
        {
            f[p[Len][0]]=(!p[Len][4])?p[Len][2]:f[p[Len][4]];
            b[p[Len][0]]=1;
        }

        if (!Len) return;

        if (b[a[p[Len][5]][0]])
        {
            if (f[a[p[Len][5]][0]]>f[p[Len][3]])
            p[Len][4]=p[Len][3],p[Len][3]=a[p[Len][5]][0];
            else
            if (f[a[p[Len][5]][0]]>f[p[Len][4]])
            p[Len][4]=a[p[Len][5]][0];
            p[Len][5]=a[p[Len][5]][1];
        }
    }
}

void Fd()
{
    int i,h,t;

    h=0,t=1;
    D[1][0]=T;
    D[1][1]=0;
    b[T]=1;

    while (h<t)
    {
        for (i=ls[D[++h][0]]; i && !b[a[i][0]]; i=a[i][1])
        {
            D[++t][0]=a[i][0];
            D[t][1]=h;

            b[a[i][0]]=1;

            if (D[t][0]==S) break;
        }

        if (D[t][0]==S) break;
    }

    for (; t; d[++m]=D[t][0],Bz[d[m]]=1,t=D[t][1]);
}

bool pd(int t)
{
    int i,j,cut,lastcut;

    cut=0;
    fo(i,1,m-1)
    {
        lastcut=cut;

        for (j=ls[d[i]]; j; j=a[j][1])
        if (!Bz[a[j][0]])
        {
            if (lastcut+f[a[j][0]]>t)
            cut++;
        }

        if (cut>i || cut>t)
        return 0;
    }

    return 1;
}

int main()
{
    freopen("mountainview.in","r",stdin);
    freopen("mountainview.out","w",stdout);

    scanf("%d%d%d",&n,&T,&S);
    fo(i,2,n)
    {
        scanf("%d%d",&j,&k);
        New(j,k),New(k,j);
    }

    Fd();
    init();

    l=0,r=n*2;
    while (l<r)
    {
        mid=(l+r)/2;

        if (!pd(mid))
        l=mid+1; else r=mid;
    }

    printf("%d\n",l);

    fclose(stdin);
    fclose(stdout);

    return 0;
}

后记

终于把坑填完了。。。
人工栈真™难写

还有这道题根JZOJ5388 一模一样
改个文件名交上去就A了
(不过那题数据极水

ak2新版内核 AceKard All-In-One (AK-AIO) v1.5 ---------------------------------- Credits ------- AKAIO: By Normmatt (http://normmatt.com), normmatt234 \AT/ gmail \DOT/ com By Smiths of Emuholic (http://www.emuholic.com), smiths \AT/ emuholic \DOT/ com By gelu (http://code.google.com/p/acekard-3in1/) Based off of AKBBS' source contributions from the above and following authors: Moogle bliss (http://bliss.hanirc.org/blog) kzat3 (http://kzat3.cocolog-nifty.com/blog/) Special Thanks: bd2rae (http://bbs.yyjoy.com/thread-45884-1-1.html) What is This? -------------- AKBBS has been usurped thanks to amazing efforts of Normmatt in merging firmwares! AK-AIO is custom system software for *BOTH* the AceKard RPG and AK2 (and preliminary AK+ support), using all the features from the latest release of AKBBS(1.99) as a base. One file, two cards... with hopefully a third fully supported soon enough. Base features ------------- For those unfamiliar with all the additions the AKBBS (now AIO) software has in comparison to the stock firmware, here's a sampling of the bigger changes: * Cheat Improvements - R4/XML Cheat File processing, online updating * Plug-ins for TXT/MP3/etc. * "Future Adaptable" Multi-loader support (AK2) * Multiple Save Slots per title - with copying between slots * Slot-2 Integration - EZ3in1 (w/GBA Patching) and older FlashAdvance Pro carts * Shortcut tweaks * Multi-page Start Menu * Filetype-based external icon support * Per-Rom settings for soft-reset/download play/cheats * Copying/Cutting/Deleting SAV files along with NDS files * Several improvements to 2byte language support * SAV backup/restore from within GUI (.SAV.BAK) * Wifi updating of Cheat Database and Loaders Version History --------------- AK-AIO 1.5 + Fixed issue with the hiddenFileNames globalsettings option not accepting non lowercase filenames. + Optimizations to the AK2 dldi should be a little quicker now. + Update Dutch translation (Thanks MarioWaza). + Update Spanish translation (Thanks Pendor). + AK2/AK2i clones are now officially unsupported. + Gba icon has been removed from main selection screen on DSi. + Removed outdated plugin system. + Per rom GBA frame support (256x192x15bpp) - Place BMP with internal game id of gba rom in __aio/frames. + Added support for save sizes up to 256Mbit (32Megabyte). + .sav is now default save extension. + Reverse Alphabetical List sorting (set sortListAlpha=0 in globalsettings.ini). + Auto-Anti-Piracy Patcher updated. + ARGV support for homebrew. + New DSi detection (Shouldn't show slot2 icon after softreset on ak2i now). + Disable start menu by adding "LockStartMenu = 1" to your globalsettings.ini + Fixed Trainer Toolkit support. Please refer to LoaderChangelog.txt for compatibility fixes. AK-AIO 1.4.1 NOTE: It's recommended you delete your optionlist.bin file in the __aio folder when updating to this release as the file structure has changed. + Soft reset Improvements. + Fixed corrupt Language files (Italian, German and Japanese). + Added missing font needed for chinese. + Added setting for Hide Extensions to the settings window. + Fix optionlist.bin corruption. + Spin boxes wrap around. + Game Fixes (DMA-Save Mode): - Princess Maker 4 - Club House Games - Mario and Luigi RPG 3 - Rune Factory A Fantasy Harvest Moon - Animal Crossing (Currently cannot be run in this mode, force usage of DMA mode). - Hidamari Sketch Dokodemo Sugoroku x 365 + Game Fixes: - Grand Theft Auto Chinatown Wars (U) Thanks gelu. - Mario and Luigi RPG 3 (J) (new patch, thanks gelu). - Layton 3 (J) (new patch, thanks gelu). - Animal Crossing. + Updated French language (jp33). + Fix backlight always enabled on DS Phat. + Fix the Per-File icon problem if you have similar games (e.g. - Golden Sun.gba and Golden Sun 2.gba) - In blissland, GOLDEN~1 is the same as GOLDEN~5 + Wifi Updater has lots of fixes relating to GBATemp's new, crappy, server and its timeouts - We appreciate the hosting, but seriously... everything needed to be rewritten to adapt to the crap speeds NOTE: DMA-Save mode is now default so DMA mode (red loading text) is now enabled by holding X during loading. AK-AIO 1.4 + Settings window uses tabs now, merging Settings, Advanced Settings, and Patches options (Thanks Gelu) - Use L/R to cycle through tabs + Misc cleanup of the gui. + 3in1 options now have FAS1 settings merged (detects 3in1/FA at selection, displays options accordingly) + Language files have some addition "title" additions/changes + Leapyear code fixed because the DS sucks at reporting variables nicely. + Updated German language (moviecut). + Reset more of arm7 before runing a game (Thanks Gelu). + 3in1+ Fix for Opera (Untested, Thanks cory1492). + Game fixes: - 3369 Mario and Luigi RPG 3 (J) fixed. AK-AIO 1.3.5 (Unreleased) + Game fixes: - 0645/0777 Star Trek Tactical Assault - General save fixes. (Thanks Gelu for noticing a silly bug). + New Patching Mode hold X while launching a rom. - Fixes video and sound glitches which occur in old patching modes. - NOTE: This is still experiental so it isn't default. + Folders now show their size in the Info window. + Soft Reset fixes. AK-AIO 1.3.1 (Unreleased) + Game fixes: - 1752/2314 My Spanish Coach fixed. - 2243/2412 Pokemon Mystery Dungeon Explorers of Darkness fixed. - 2385 Daigasso Band Brothers DX fixed. - 2906/2971 Star Wars The Clone Wars Jedi Alliance fixed. + Unnecessary Guru Meditation screens on the AKRPG is fixed. + Soft Reset fixes. + Copying files should work better. + Game icons that rely on the nds firmware's background will display properly (Thanks Gelu). + Misc cleanup. AK-AIO 1.3 + AK2i support (options that could potentially harm AK2i are disabled) + Loaders are now external and can be updated separately to the GUI. - Updated Wirelessly! (choose Loader Update in Wifi Update option of Start Menu) - Small changelog, download, update all possible - Loaders only updated for card being used (e.g. - AK2 users only download ak2loader) - Resume supported - Many loaders are beta, know this and shut up - Manual download page @ http://akaio.gbatemp.net/loaders/ + Wifi Cheat Update has resume support! - Prompts after confirming you wish to "Try Again" + Files are now sorted alphabetically (Forced at the moment, sorry). + Added Some of Gelu's patches: - Faster Directory Listing. - New List mode - Internal nds names. - Lots of Soft Reset Fixes for the AKRPG. - new DMA mode and BBDX save fix for the AKRPG. - font system (fully supports unicode now :D). - New FIFO IPC System (Behind the scenes stuff). - Massive amount of soft reset fixes mainly for the AKRPG. - Game fixes (Brain Age 2 (K), Chrono Trigger (U/J),...). - Added a few game related fixes (Think Kids, Tropix, Bleach 2). NOTE: because of new font system, language files now need to be utf8. Some have been converted such as English and Japanese but others will need to be saved as utf8 to work properly. + Japanese games now show Japanese characters in rom info window when language isnt set to Japanese + Added a few game related fixes (Yoshi's Island, Star Trek, NSMB). + Files are now sorted alphabetically (Forced at the moment, sorry). + Pokemon Diamond/Pearl/Platinum can now read saves for R/S/E/FR/LG from ewin and 3in1 (AK2 Only for now). + Cheat engine fixes. (AK2 and AKRPG only for now). + Optimizations all round (Shouldn't have any lag in GUI anymore, also shouldn't experience any lag while saving). + Italian language added, language updates for English + New 3in1 options window. + Show GBA internal name in Internal view mode. + 3in1 internal GBA rom header stuff and work on Save/Load prompts in 3in1 options window. - Enable/Disable saving 3in1 SRAM on startup (Enabled by default) - Enable/Disable prompting before saving/loading SAVSRAM (recommended!) - Enable/Disable the Universal Sleep Hack for GBA games - Blank NOR button added for quick erase - Dump SRAM button will manually dump the SRAM to a timestamped .sav file in the root - 3in1+ support (untested, but routines and discovery are in, Opera and Rumble sources not available yet) - Thanks to all donators! + Fixed some issues with the cheat window. - Folders that only allow one cheat selected now function properly - Separate icon for skinners for single-select folders (see included skins) + Animal Crossing cheats on AK2. (Use the v1.1 rom as v1.0 will not work anymore). + Unicode font loads on a per-ROM basis - Default font is "kochi-mincho-subst.pcf" in /__aio/fonts directory, old unicode font removed (was 2x the size) - Skinners may add their own custom font to their ui's directory - New line in uisettings.ini "customUnicodeFont = xxxxxx.pcf" will load that font instead of default + Ability to hide extensions by manually adding "hideExtension = 1" to globalsettings.ini + DMA mode on AK2 (Hold A while loading a game to use non-DMA mode: Red text = DMA / Blue text = non-DMA). + New Super Mario Brothers Minigames on AK2: If they don't work, set Download Play to "Disabled" and boot in non-DMA mode (hold down A while loading) + Misc bug fixes (Too many to list). AK-AIO 1.2 + New AKRPG/AK2 Detection Routine which has proven to be much better + Cheat Update functions run from plugin, giving full memory access to it and allowing updates without full AKAIO updates - Can choose to download USRCHEAT.DAT or CHEATS.XML and whether or not to display "Whats New" before launching - Should be much more stable, perhaps a teeny bit faster - Third option in "which cheat file to download" box displays the setting window at plugin launch, can be used for future expansion + Uses gelu's latest fixes for BBDX on the RPG (only works from MicroSD) - excellent work, gelu! - Also has some other fixes gelu's put in for 3in1 NOR erasing, etc. - gelu = the AKRPG master. + Preliminary AK+ Support. Very preliminary. As in, no help offered but know it's still being worked on (See: AK+ SUPPORT) + New Experimental Cheat engine for AK2 and AKRPG, please report any bugs + EZIV compatiblity fixed without need for special line in globalsettings.ini + Scrolling Non-unicode Cheats/Notes, toggle in Advanced Options (default: on) - Can also call cheat window in ROM Properties with SELECT (if button is visible) + Simple Internal Text Reader - System Settings -> TXT Viewer - Parses text, add bookmarks with X, scroll between bookmarks with L/R Buttons - Not as fast as native TXT plugin due to pre-processing of text files, perhaps if we had the TXT Plugin source things could be done, but that would make sense. + Per ROM rumble settings, ROM Options window + Listview mode remembered + 3in1 Support should be fixed, with thanks to cory1492 for testing + GBA Frame issue with Slot-2 booting from main list fixed + Asian languages should be better supported, since we're compiling the menu with DevKitARM 21 + Variable Height Scrollbars and clickable arrows in cheat window/internal TXT viewer. 3 new BMPs for skinning: scrollbar_t.bmp/scrollbar_m.bmp/scrollbar_b.bmp + Super awesome hidden poweroff button in help window, add your own "poweroff.bmp" to "__aio" for fun AK-AIO 1.1 + USRCHEAT.DAT wifi updating support from within shell - Connects to Narin's GBATemp site, displays WhatsNew.txt, downloads, unzips, replaces in one step - UpdateDB option in Start Menu -> More -> UpdateDB - zlib thanks to GPF (http://gpf.dcemu.co.uk/) - Download speed limited by DS routine IPStack + (AK2) Alternate loader support, place loader(s) in "__aio/ak2loader/" - ROM options window, select the AK2 loader to use to launch ROM - Compatible with AceKard official loaders + (RPG) uses gelu's latest 4.09e13 softreset routines - Updated 3in1 routines to all of gelu's latest + Fixed Dragon Quest 5 (AK2/AKRPG) - Can now get off the ship and save file wont be rolled back + Can change save file extension (.nds.sav or .sav) - Extension conversion: .SAV file Info Window, press "Save Ext." button - Will convert all Save Slot SAV files as well + Scans for cheats on ROM Info Window (.DAT only), if exist "Cheat" button displays + Per file icon support (32x32x15bpp) - place BMP with same name in same dir as file (eg: nesDS.bmp for nesDS.nds) + (Source) Variable spinbox width/General cheatlist cleanups/Scrolling Messageboxes + (Source) Minor changes to the cheat window + Fixed save size problems - Shouldn't have any more problems with save sizes + Misc Skinning fixes - Fixed problem with Adv.Evo skin - Form titles moved up 1 pixel + SAVBAK routines now use native AK functions AK-AIO 1.0 + Runs on both AK2 and AKRPG + Uses gelu's latest AKRPG rom loader + Uses latest AK2 4.07a16 rom loader + Contains everything from AKBBS1.99 + Future support for larger than 4mbit save types (only supports 64mbit at the moment) + Applied Bliss' AR Engine fixes to the AKRPG + Hopefully fixed most of the soft reset issues with the AKRPG Special Notes ------------- Seeing as this release has experimental support for saves ranging all then way up to 128mbit, please err on the side of caution and backup your saves before using this firmware. The "__RPG" and "__AK2" directory is now simply called "__AIO" Existing users should make sure to rename their system directory, and update globalsettings.ini to reflect the new hidden directory. AK+ SUPPORT --------- AK+ support is very experimental. It has been reported you need to download the software from the following URL: http://www.acekard.com/download/ak+/akmenu_4.07_for_akplus.zip and extract the "akmenu2_fat.nds" to the root of your SD card to even attempt to get things to load. AK+ support is constantly being worked on, but know it's not really "supported" yet. Known Bugs ---------- There are no known bugs ToDo ---- * Keep working on Acekard+ support * Fix any bugs that crop up Also ---- Cheats included are from Rayder's awesome compilation at GBATemp, now maintained by Narin, and are current as of the date of this release. For the most up-to-date files, check GBATemp's release site (http://cheats.gbatemp.net/), either via PC or by using the "UpdateDB" option in the start menu.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值