心累,昨天一天3个比赛,全部炸掉,这个陕西师范的比赛我真的读不懂题目,只搞出来7题,难受
A,B,F签到题,不讲了,只讲C,D,I,K
链接:https://www.nowcoder.com/acm/contest/121/C
来源:牛客网
空间限制:C/C++ 131072K,其他语言262144K
64bit IO Format: %lld
题目描述
iko超级超级喜欢吃糖,有一天iko想出去玩,她计划从1点走到N点(按1,2,3,...,n的顺序走),每个点都有一个补给站,第i点的补给站有a[i]颗糖,从i点走到i+1点会消耗掉b[i]颗糖,iko在出游的途中可以选择三个补给站,iko想知道她走完全程到达N点时口袋里最多还能剩下几颗糖(初始时iko的口袋里一颗糖都没有)。
输入描述:
第一行输入N(3<=N<=1000)
第二行输入N个数代表a[1].......a[N] (0<=a[i]<=1000 )
第三行输入N-1个数代表b[1]......b[N-1] ( 1<=b[i]<=1000 )
输出描述:
输出一个数字表示iko到达n点时口袋里最多剩下的糖,
若不能到达N点输出-1。
输入
3 1 3 4 3 4
输出
-1
输入
5 3 4 5 2 4 3 2 2 2
输出
3
分析:DP题目,建立一个二维数组DP[MAX][4],代表i点,领取j个补给站后的糖果数,和二维0-1背包差不多,2重循环,每一个i,对应3条路,每到一个i站,就要把之前糖果数全部计算出来。
1 /** 2 3 :;LaEaHKEEGpPXU7;, 4 .:75pKH11252U252XapZgRQgD6XJscLr;,. 5 :LXpRgGaX521JLw1JswJJsJs22XHPPEZEGDOMMRDOa7. 6 .r2EDDZEpZPZP6KpHX5SXH5XXa5KwaXaSX5UJ1c77sLs2GMQQ6r . 7 ,LpgOGpEZGZEZEpZKpHHU5wP5HEDgpXpHa2SSa5aSXULr7rrirrJXRBp; ;B 8 ,J6MRZH6EgEEZE6E6EZZPZXXwSSGQXr::aPpP5USUHaHaKa5Lvrr7ri;rLHBB2: Kc 9 rpQDOpPPOGGZOGOZG6GEOEOEDPPGBa. .PaSSUXSUUUaUSaKXKS177r7rrrirSBBR7 .O, 10 :UBQOKPK6ZOOOEDEO6GZE6EpEpDgDBR: UBpXHa5aSaUS5SUS5XapPHJc7rrv7rr7sgBBs .g. 11 ;gBMPXpO6GEOEOEOEGEOEE6EZEEDRGBB EB5pKSXpHKaHSX552S5aUHHEX17c7vr7777s5RBS: .R; 12 .sQBPXpDZOODOgODGOGgEDEOEOGgGgOOMB: LBKKSXSHa52aaKXHXKaa5aSaaHXSJLcL7vcc777JDBBg2;. Qi 13 ;2ggp2EDDOggGEDGgDDOgGGZDOOZOGg6gEBX vBZaHUKaaUXXXSXXKXpXHXH5wwaa52U1wssLsLJccv1UDQBQ67. O7 14 :ZZUU5PROOEOZOZGGOODZOGgODZOOgOggRgRB; ;:..R6XaKKpP6PGppKPHpHpPX5aU21UUa5Sw52UwUJJv77L77sSpQMDU; ;B5 15 ,SRJ7sSHGggEOZOEG6OODpOZgggOQQBBBBBQBBQ.,;;. LBOgOgDRDDZODMgQRgRDaa552a252UUa25w5UaU2sLvccs7r7sJZBBMr ,XQJ: 16 LQHr77J6RGOZDZOEGEDGgDRORQBBBQRDPU1Jscwa7.,::.:J7r;::::. ..,:;i7UOgRRRgDPH5SUSU52U2HHa1JJJLJLccLr71RBB, 7R2, 17 :RZv;77JSgGOZEODEDGOEggQBBBMS7;:,:,,.,.,.:7L;:,;.: ,: . ..... .:;rJU6GgGRggEZHPaKXX2S221Js1Lc7r:7QB. .XX: 18 7g1;;7rcXG6gpGDZGgZOOQBBQpr. ::::;:;:::Jr::sr;::;:.:vs,:::::::::::,, ,:7L5HGOggRgZUUU5wSUaJLc7r7BOiDr ... 19 .XX;;;irLHGKpZZZEKgDRBBB6i ,;;:;;;;r;;:s177:,;L7:;7:.rHi,:::::::::::::::::,. .,;7ZRQgO6KUUJsLwsJ7KBM. ..... 20 JZ:;rrrc5EPHp6XgpRBBBE; :i:;;;;;:;;;:c7::r7;,::::::::rv:,:::::::::::,:,:,:,,,, .;sORQRGX21wsXU: .... . 21 .Br;iir72EHPHZ6EgBBR7. ..;ii:;;;;;;;;;:71r::.:7, .::7;:;H;.::,:j::::::,:::::,,,::,,, ,7wEDRZBMr ....... 22 1D;:r;rwOPXPKH6BBX, .:;:;;;:::;:;;;;;::Ls,;ss..r. ,c77;sLU,:,:::,:::,:,:,:,,,:,,,:::. .:.rP:....... 23 D2:i;rJpKHXHXgg7 .,,::::;:::::;:;:;;:;SL7sS2, :. ::::,:U7.:::,:::,:,,,,,:,,.,,,.,:, ;L:. .. ... 24 :Qc;i7LGZPa6gBM, ...,,::::::::::::;;::;.JJ;ic: ;:::,v1,.:::;7,,,:,:,:,,,,.:,,,,.. :2wr. ....... 25 sRr:rrwZGgBQR7. .,,::::::::::::::;::;:::Hr:7i ,;;:::U: .,,,:r.,,:,:,:,,,:,,,..... 7K2:. .......... 26 OX:irsXgQZ:. .,,:::,,:::,::::::::;;;::r5;r7: :;;;:7L ..,.,;:,:,:,,,:,:,,,,...... .rU6w;.............. 27 .BJ71EK5;. .,,::,:,:,,,:,:,::::::::;:;.Ls;r7 :;:::s, ..,,,r:.:.,,,.:, .,..... . .;s5XJr,..,............. 28 1Mv::. .:,:,,,,,,,:::::::,;:::;:;::..J7;c: ,. ,rri:27 , .,:;. ,:,:,,:..,.... .rpPL;:.. ... ............. 29 ..7Ls: .,,,:,,,:,:,:::,:,:::::,:::::: .Srrr, .,:;;;::::..:7r;r1 .: :E:..,,:,...,,.., ..XBQ7, ................... .. 30 ,;7v7r7:, ,,,,:.,,,,,,:,,::,:,,.::.,:.,:, :Jrr; ,r7,:.. ,:::L: . .7RJ .,.:.,......,,:MBs ..............,........ 31 .:;vJs7i, ,,,., ..,,:,,,:,,,:,:.,rs,,.:,, ;J;c, .,::;; Lr.E: .,...,....:,:1Z: .........,.,...........:,. 32 .;,,:r7J1wv;,. ....,.:. .,.,,:,,,:,,::::,sS;.:::, cLrr. . .,. .,..: ;; r5 ........,,:;s7. ....,.,.,...........,.,.,,. 33 ,BBs::: . ........,.,,,,,.:,,,:,:,,.;s7r,,,,, cc7; ,.,,. .:7rrJGMPOEL1, ..... ,,:rSr, : ,.,.,.,.,.........,,,,,. .. 34 rZL. ....... ..,,,.,,,..,,,.,;,...7J:s: .. .wr7, ... .rJpQBBBBBBBQgKP77s .. .,7S2,,....,....,.,.,......,,.,. .:cX2 35 ;SH7, . . . .. .,.,.,.,,,...,..r, ::Ur;7L . .57;. .rPBBQBBBPws:;r::::.,:P. .;S5;,..,...,.,.,.,.... ..,,, ..,7HSJvr 36 r7r;: . ... ..........,...,.. 7L;,rS;;ivr . 1r: . .rZBBK7;.JL,::Jrs;.:;,:;J, .,;LDv..:.,...,.,.,.,...,.,,:,, ,7sKGwc77; 37 .:7L7:, . ,r,..,.,,,...,..:iLL 7s;r;cv: U7. :vi;:. .. :Er:::.Ls. . ,7::::vHEi ,:,,.,,,.,.,,,,,,::::, .:1QBKJJUsssc 38 .:rvw1JsL7;, ,;..........,.:ir :r .ELr77v:,. Pr .. . Ls ,w. rr.r:JPr. ::,..,,,.,,,,:,:::,:,..7XgRE52US25w1c 39 .:;7JRQpX: ; .........,i: .,J ;gri;7r : 1; .X: . ,v :aK1, ,,:.,,,.,,,,:::::,;::::cOBB6K55UXUX5XUw 40 ;J,XQB7,: . ...,: .:7Z.7Zi7;r: , v, :w:;,.,:::7LUsc:..:,:.:,,,,,:,:::::::,:;c5BBPS5wSUSUaUaUa2 41 J7 rEBBg..,. ..... . ,L1PLKr:,:;r;;::, :, :;SXsJU1XLLr....:,,,,,,::::,::::::,::LL,,rZXUJU25552aUUUU 42 JL .:sXBB:... ., . ,OH777;,rZRBBBQL ..r, ,:r7::r:,;;....:,,,,,,,,.::::;::;:::.7gL UK2UUS1aw2wU25J 43 U7 .r71BB; . :.. .. :QJ;.;1pBBBBBGRBRi i: . .w7. ..,,:,,,,,:,:,:::::::,.,2BR: .DSaUSUUS525w5U1 44 2r :7rJBQ7 .;. . KL::JGBBBgE6Hp6XMQ; . ... ,2s ,,,,:::::,:::::::,,.:sQQB2 ;DHa5U52S2U25USJ 45 a: :7;1BB2 .v, sL;LPQgDBPH6KPQBpGBG . ... .. aP:. .. ,::,:::::,,,,.;rSgBQDa; :gSSwSUUU525US2U 46 5; ;;r2QBB, .s: :a7:PBZ2,:BEaZPKgBZOgB, . ...:LEHri::,:.,,.,,,::rsXRBgGKEJi, 2GH252SUS5S11wH5 47 U: ;:rwDBBr .c, rB6r 167.,,RQPpEP6OpKEBc ., . : ::sS7;cKB6HHa1XOQRRQBRgEZDBH; .. ;RZUPSSU525USSpK2 48 s; ;::aBg, .; .Gv,H::,,::,;BQDOGHPXpKBs .,. . .,. .r:;:6gOEBQRRRDggQgOHgMGL, .;PEHHXaaKaPXPKPaXS 49 s7.:,sBa :..S, vE::::; 7BBMgZH6pQBr . ,:, ,.,r2RHSSpMZPKRRZpgggav, ;UpEZaaaKHHUHPPaUJHGO 50 a;.775: .::rU. gR:,:. :;:BBBBQar . ,, ,.,7rggJwU6DDGMgOGgXc:, ,rPGOpKSXSXSKUKHU1UHgOEP 51 1i :SZJrLXpBBMRB: .v Ba,. :sv: . irsBUSpEEGPPpg65r:..,;sKZDZHSX5XaHU55K2wUGMRZ6Z6 52 :K :7asvwc2MgEQB, :gg.:iB7 .,,,:. ...,. . .. .:iM6GEpSSXZOEs:...;spZpKKXXSX5Xa5Ja5wwKGQDEpp6OZ 53 w; ,LXLr77sLwL5aR. gRgQgaQBi ,vJwvi,. .;;:;7: . . ,... rRDRJUSXpgas:,.:;U66SaHa2X5aUa552X12SgQgpZpEpGOD 54 H: ;XJ;77rv7rJUaQ;rgaPgXXHBB; . . .ri:;; ,: . :6QZEKHXpXXL:,::r1PKXaa2XSS5a5S5UJ22aOBgEpOppZOOgG 55 iwsJsr7rsLrrLcJ2gQGXHwa1SUHBB: . ... . .., : 1BRKpOEGp2Jr;::rsXP1Uaa2U5a5aUa5SsSpgQRZGZEEZZOOgDg 56 ,cs5aXaP552ssLwRSHXaSS5asXBB. . . . LBBgGgZHsr;vrr;rcXpP5UUS5X5S2XS5SS1URBggpEZgDDGOGggRD 57 ,;irrs2KgQRPJJJSUXKXSHJpBM . . . ZBBOUsr;:. ,,,rHgZPUaSaUSUSSXaUPXsSBB6ZZp6EEGOOGDEggO 58 ;BBQQZaSJ5J15SJDQ7 .iEBL:. . .,:,:;SRQGZXPXXSHaS2UUSUSswQB6OZgG6pZZGODEOGDE 59 JgUri1aGEpEpXSS5LBQ, .rLap2Jr ;712OO6ZggRDZXHXpKK2211LLLc7wgBa2PODRGE6OZgDgGDGD 60 7QB; ,Jc76DaZXOZgDPEBBX, :c1HEZ1c;:,.,:;cHDgQQggMZgGOZO6OEGpXsLLsJXHPOBBBc;vss5EMggZDODOgED6 61 LZJ::iwrrr72EPgXU5OBBBBBBBp7: .i5P6wL;, .:LS6DMgMgZKgEOPOGGDDGEXULvLSOBBBBBQBgDQDJ5rrr7JOQQDDZGEgDD 62 wp rR5, .HQRX7r72RQBBBBBQBMEK6Uc7sc7cHOU:, .:LHgOQg6ZOPZpZGGEDERZPwcr7LKDDaJr:. rBX;;:r:ir1DBQMgRgDp 63 7D,sw: , Z. .LgBBQBBOsJaQBBBBBBXrr. .:rwZBBQgROgDgDOERRMgROOScrLsPP5r, 7Qs,::::::rUgRgZOG6 64 ,Q57:r ,: ,r U: .;; .vL7L;r:UG7.:sr;JSgQBgDEZXXUSXpHa21svr7r7s2v:. iQK...:,:::;LLJJws 65 OBHs;. :;;,v H: :6X; rpL;7pSrrr7r;::,....,,:;iirrvvvr, :BBPs;;:,,,,::;:: 66 ::rPDEL:..7:c;7r pK .: :KL.:r:.. ..:icsS5sr:,. JgGgBQDOSJss77r 67 :r;::: , PH r, ,;5: ,::::;7Ls7Lc7;: ,:7JP17rJUs 68 .:J: :; .,:K6BQS7:.,.,. 69 :r7Ji;r7;::;;. 70 . **/ 71 72 #include <bits/stdc++.h> 73 using namespace std; 74 75 #define FF(a, b) for(int i = a; i < b; i++) 76 #define RR(a, b) for(int i = a; i > b; i++) 77 #define ME(a, b) memset(a, b, sizeof(a)) 78 #define SC(x) scanf("%d", &x) 79 #define PR(x) printf("%d\n", x) 80 #define INF 0x3f3f3f3f 81 #define MAX 1001 82 #define MOD 1000000007 83 #define E 2.71828182845 84 #define M 8 85 #define N 6 86 typedef long long LL; 87 const double PI = acos(-1.0); 88 typedef pair<int, int> Author; 89 vector<pair<string, int> > VP; 90 91 int main(void){ 92 #ifdef LOCAL 93 freopen("in.txt", "r", stdin); 94 freopen("out.txt", "w", stdout); 95 #endif 96 ios::sync_with_stdio(false); cin.tie(0); 97 int i, j, a[MAX], b[MAX], DP[MAX][4], n, ans; 98 99 cin>>n;FF(1, n + 1) cin>>a[i];FF(1, n) cin>>b[i]; ans = -1; 100 DP[1][0] = DP[1][1] = DP[1][2] = a[1];DP[1][3] =0; //初始化1点的糖果数 101 102 for(i = 2; i <= n; i++){ 103 for(j = 0; j <= 3; j++){ 104 DP[i][j] = DP[i - 1][j] - b[i - 1]; 105 if(DP[i][j] < 0) DP[i][j] = -INF; //此路不通 106 } 107 for(j = 0; j <= 2; j++)DP[i][j] = max(DP[i][j], DP[i][j + 1] + a[i]);//走到i点时的糖果(只走3条路) 108 } 109 for(i = 0; i <= 3; i++)ans = max(ans, DP[n][i]); 110 cout<<ans<<endl; 111 112 return EXIT_SUCCESS; 113 }
链接:https://www.nowcoder.com/acm/contest/121/D
来源:牛客网
空间限制:C/C++ 131072K,其他语言262144K
64bit IO Format: %lld
题目描述
ZQ是一个拥有n女朋友的万人迷,她的每一个女朋友每天晚上都会挨个给他打电话,要他讲了睡前故事才能睡觉。可是,每次他的女朋友都会挑他在吃鸡的时候打电话,ZQ总是因为挂机被舍友赶出宿舍,于是,ZQ告诉他的女朋友们,别打电话了,他会主动打过去给他们讲故事,再打电话就分手!
于是,ZQ把他的女朋友名字写在纸上,画成一圈,顺时针编号为1~n,然后从1开始顺时针数。在每一次数数中,ZQ数k个就停下来,然后给选中的女朋友打电话讲故事。
现在需要你按顺序告诉我们他给女朋友打电话的顺序输入描述:
先输入一个t,然后t组数据,每行包含两个数字n,k,n<20,k>0
输出描述:
按顺序输出每轮被选中的女朋友的编号。
输入
3 10 3 5 2 11 4
输出
3 6 9 2 7 1 8 5 10 4 2 4 1 5 3 4 8 1 6 11 7 3 2 5 10 9
分析:orz,这题和CFdiv3#481的C题比较类似,一个循环无限遍历1 ~ n + 1,a==k就归零,保存i,标记一下当前位置,考思维。
1 /** 2 3 :;LaEaHKEEGpPXU7;, 4 .:75pKH11252U252XapZgRQgD6XJscLr;,. 5 :LXpRgGaX521JLw1JswJJsJs22XHPPEZEGDOMMRDOa7. 6 .r2EDDZEpZPZP6KpHX5SXH5XXa5KwaXaSX5UJ1c77sLs2GMQQ6r . 7 ,LpgOGpEZGZEZEpZKpHHU5wP5HEDgpXpHa2SSa5aSXULr7rrirrJXRBp; ;B 8 ,J6MRZH6EgEEZE6E6EZZPZXXwSSGQXr::aPpP5USUHaHaKa5Lvrr7ri;rLHBB2: Kc 9 rpQDOpPPOGGZOGOZG6GEOEOEDPPGBa. .PaSSUXSUUUaUSaKXKS177r7rrrirSBBR7 .O, 10 :UBQOKPK6ZOOOEDEO6GZE6EpEpDgDBR: UBpXHa5aSaUS5SUS5XapPHJc7rrv7rr7sgBBs .g. 11 ;gBMPXpO6GEOEOEOEGEOEE6EZEEDRGBB EB5pKSXpHKaHSX552S5aUHHEX17c7vr7777s5RBS: .R; 12 .sQBPXpDZOODOgODGOGgEDEOEOGgGgOOMB: LBKKSXSHa52aaKXHXKaa5aSaaHXSJLcL7vcc777JDBBg2;. Qi 13 ;2ggp2EDDOggGEDGgDDOgGGZDOOZOGg6gEBX vBZaHUKaaUXXXSXXKXpXHXH5wwaa52U1wssLsLJccv1UDQBQ67. O7 14 :ZZUU5PROOEOZOZGGOODZOGgODZOOgOggRgRB; ;:..R6XaKKpP6PGppKPHpHpPX5aU21UUa5Sw52UwUJJv77L77sSpQMDU; ;B5 15 ,SRJ7sSHGggEOZOEG6OODpOZgggOQQBBBBBQBBQ.,;;. LBOgOgDRDDZODMgQRgRDaa552a252UUa25w5UaU2sLvccs7r7sJZBBMr ,XQJ: 16 LQHr77J6RGOZDZOEGEDGgDRORQBBBQRDPU1Jscwa7.,::.:J7r;::::. ..,:;i7UOgRRRgDPH5SUSU52U2HHa1JJJLJLccLr71RBB, 7R2, 17 :RZv;77JSgGOZEODEDGOEggQBBBMS7;:,:,,.,.,.:7L;:,;.: ,: . ..... .:;rJU6GgGRggEZHPaKXX2S221Js1Lc7r:7QB. .XX: 18 7g1;;7rcXG6gpGDZGgZOOQBBQpr. ::::;:;:::Jr::sr;::;:.:vs,:::::::::::,, ,:7L5HGOggRgZUUU5wSUaJLc7r7BOiDr ... 19 .XX;;;irLHGKpZZZEKgDRBBB6i ,;;:;;;;r;;:s177:,;L7:;7:.rHi,:::::::::::::::::,. .,;7ZRQgO6KUUJsLwsJ7KBM. ..... 20 JZ:;rrrc5EPHp6XgpRBBBE; :i:;;;;;:;;;:c7::r7;,::::::::rv:,:::::::::::,:,:,:,,,, .;sORQRGX21wsXU: .... . 21 .Br;iir72EHPHZ6EgBBR7. ..;ii:;;;;;;;;;:71r::.:7, .::7;:;H;.::,:j::::::,:::::,,,::,,, ,7wEDRZBMr ....... 22 1D;:r;rwOPXPKH6BBX, .:;:;;;:::;:;;;;;::Ls,;ss..r. ,c77;sLU,:,:::,:::,:,:,:,,,:,,,:::. .:.rP:....... 23 D2:i;rJpKHXHXgg7 .,,::::;:::::;:;:;;:;SL7sS2, :. ::::,:U7.:::,:::,:,,,,,:,,.,,,.,:, ;L:. .. ... 24 :Qc;i7LGZPa6gBM, ...,,::::::::::::;;::;.JJ;ic: ;:::,v1,.:::;7,,,:,:,:,,,,.:,,,,.. :2wr. ....... 25 sRr:rrwZGgBQR7. .,,::::::::::::::;::;:::Hr:7i ,;;:::U: .,,,:r.,,:,:,:,,,:,,,..... 7K2:. .......... 26 OX:irsXgQZ:. .,,:::,,:::,::::::::;;;::r5;r7: :;;;:7L ..,.,;:,:,:,,,:,:,,,,...... .rU6w;.............. 27 .BJ71EK5;. .,,::,:,:,,,:,:,::::::::;:;.Ls;r7 :;:::s, ..,,,r:.:.,,,.:, .,..... . .;s5XJr,..,............. 28 1Mv::. .:,:,,,,,,,:::::::,;:::;:;::..J7;c: ,. ,rri:27 , .,:;. ,:,:,,:..,.... .rpPL;:.. ... ............. 29 ..7Ls: .,,,:,,,:,:,:::,:,:::::,:::::: .Srrr, .,:;;;::::..:7r;r1 .: :E:..,,:,...,,.., ..XBQ7, ................... .. 30 ,;7v7r7:, ,,,,:.,,,,,,:,,::,:,,.::.,:.,:, :Jrr; ,r7,:.. ,:::L: . .7RJ .,.:.,......,,:MBs ..............,........ 31 .:;vJs7i, ,,,., ..,,:,,,:,,,:,:.,rs,,.:,, ;J;c, .,::;; Lr.E: .,...,....:,:1Z: .........,.,...........:,. 32 .;,,:r7J1wv;,. ....,.:. .,.,,:,,,:,,::::,sS;.:::, cLrr. . .,. .,..: ;; r5 ........,,:;s7. ....,.,.,...........,.,.,,. 33 ,BBs::: . ........,.,,,,,.:,,,:,:,,.;s7r,,,,, cc7; ,.,,. .:7rrJGMPOEL1, ..... ,,:rSr, : ,.,.,.,.,.........,,,,,. .. 34 rZL. ....... ..,,,.,,,..,,,.,;,...7J:s: .. .wr7, ... .rJpQBBBBBBBQgKP77s .. .,7S2,,....,....,.,.,......,,.,. .:cX2 35 ;SH7, . . . .. .,.,.,.,,,...,..r, ::Ur;7L . .57;. .rPBBQBBBPws:;r::::.,:P. .;S5;,..,...,.,.,.,.... ..,,, ..,7HSJvr 36 r7r;: . ... ..........,...,.. 7L;,rS;;ivr . 1r: . .rZBBK7;.JL,::Jrs;.:;,:;J, .,;LDv..:.,...,.,.,.,...,.,,:,, ,7sKGwc77; 37 .:7L7:, . ,r,..,.,,,...,..:iLL 7s;r;cv: U7. :vi;:. .. :Er:::.Ls. . ,7::::vHEi ,:,,.,,,.,.,,,,,,::::, .:1QBKJJUsssc 38 .:rvw1JsL7;, ,;..........,.:ir :r .ELr77v:,. Pr .. . Ls ,w. rr.r:JPr. ::,..,,,.,,,,:,:::,:,..7XgRE52US25w1c 39 .:;7JRQpX: ; .........,i: .,J ;gri;7r : 1; .X: . ,v :aK1, ,,:.,,,.,,,,:::::,;::::cOBB6K55UXUX5XUw 40 ;J,XQB7,: . ...,: .:7Z.7Zi7;r: , v, :w:;,.,:::7LUsc:..:,:.:,,,,,:,:::::::,:;c5BBPS5wSUSUaUaUa2 41 J7 rEBBg..,. ..... . ,L1PLKr:,:;r;;::, :, :;SXsJU1XLLr....:,,,,,,::::,::::::,::LL,,rZXUJU25552aUUUU 42 JL .:sXBB:... ., . ,OH777;,rZRBBBQL ..r, ,:r7::r:,;;....:,,,,,,,,.::::;::;:::.7gL UK2UUS1aw2wU25J 43 U7 .r71BB; . :.. .. :QJ;.;1pBBBBBGRBRi i: . .w7. ..,,:,,,,,:,:,:::::::,.,2BR: .DSaUSUUS525w5U1 44 2r :7rJBQ7 .;. . KL::JGBBBgE6Hp6XMQ; . ... ,2s ,,,,:::::,:::::::,,.:sQQB2 ;DHa5U52S2U25USJ 45 a: :7;1BB2 .v, sL;LPQgDBPH6KPQBpGBG . ... .. aP:. .. ,::,:::::,,,,.;rSgBQDa; :gSSwSUUU525US2U 46 5; ;;r2QBB, .s: :a7:PBZ2,:BEaZPKgBZOgB, . ...:LEHri::,:.,,.,,,::rsXRBgGKEJi, 2GH252SUS5S11wH5 47 U: ;:rwDBBr .c, rB6r 167.,,RQPpEP6OpKEBc ., . : ::sS7;cKB6HHa1XOQRRQBRgEZDBH; .. ;RZUPSSU525USSpK2 48 s; ;::aBg, .; .Gv,H::,,::,;BQDOGHPXpKBs .,. . .,. .r:;:6gOEBQRRRDggQgOHgMGL, .;PEHHXaaKaPXPKPaXS 49 s7.:,sBa :..S, vE::::; 7BBMgZH6pQBr . ,:, ,.,r2RHSSpMZPKRRZpgggav, ;UpEZaaaKHHUHPPaUJHGO 50 a;.775: .::rU. gR:,:. :;:BBBBQar . ,, ,.,7rggJwU6DDGMgOGgXc:, ,rPGOpKSXSXSKUKHU1UHgOEP 51 1i :SZJrLXpB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;;:r:ir1DBQMgRgDp 63 7D,sw: , Z. .LgBBQBBOsJaQBBBBBBXrr. .:rwZBBQgROgDgDOERRMgROOScrLsPP5r, 7Qs,::::::rUgRgZOG6 64 ,Q57:r ,: ,r U: .;; .vL7L;r:UG7.:sr;JSgQBgDEZXXUSXpHa21svr7r7s2v:. iQK...:,:::;LLJJws 65 OBHs;. :;;,v H: :6X; rpL;7pSrrr7r;::,....,,:;iirrvvvr, :BBPs;;:,,,,::;:: 66 ::rPDEL:..7:c;7r pK .: :KL.:r:.. ..:icsS5sr:,. JgGgBQDOSJss77r 67 :r;::: , PH r, ,;5: ,::::;7Ls7Lc7;: ,:7JP17rJUs 68 .:J: :; .,:K6BQS7:.,.,. 69 :r7Ji;r7;::;;. 70 . **/ 71 72 #include <bits/stdc++.h> 73 using namespace std; 74 75 #define FF(a, b) for(int i = a; i < b; i++) 76 #define RR(a, b) for(int i = a; i > b; i++) 77 #define ME(a, b) memset(a, b, sizeof(a)) 78 #define SC(x) scanf("%d", &x) 79 #define PR(x) printf("%d\n", x) 80 #define INF 0x3f3f3f3f 81 #define MAX 1001 82 #define MOD 1000000007 83 #define E 2.71828182845 84 #define M 8 85 #define N 6 86 typedef long long LL; 87 const double PI = acos(-1.0); 88 typedef pair<int, int> Author; 89 vector<pair<string, int> > VP; 90 91 int main(void){ 92 #ifdef LOCAL 93 freopen("in.txt", "r", stdin); 94 freopen("out.txt", "w", stdout); 95 #endif 96 ios::sync_with_stdio(false); cin.tie(0); 97 int k, T, n, a, b, mark[MAX], ans[MAX]; 98 99 cin>>T; 100 while(T--){ 101 cin>>n>>k;b = 1;ME(mark, 0); 102 FF(1, n + 2){ //无限循环 103 if(i == n + 1) i = 1; 104 if(!mark[i]) a++; 105 if(a == k){ 106 a = 0; 107 ans[b++] = i; 108 mark[i] = 1; 109 } 110 if(b == n + 1) break; 111 } 112 FF(1, b)i == b - 1 ? printf("%d\n", ans[i]) : printf("%d ", ans[i]); 113 } 114 115 return EXIT_SUCCESS; 116 }
链接:https://www.nowcoder.com/acm/contest/121/I
来源:牛客网
空间限制:C/C++ 32768K,其他语言65536K
64bit IO Format: %lld
题目描述
ACM竞赛队内要开运动会啦!!!!
竞赛队内的一群阳光乐观积极的队员们迅速的在操场上站成了一支队伍准备开始热身运动。但教练看了一眼觉得队伍高高低低很不整齐。
教练想让大家从低到高站好,每次教练可以任选择一个人令他走到队首,教练想知道他要最少要进行几次这样的操作才能把队伍按从低到高排整齐(身高最低的人站在队首)。
输入描述:
第一行输入N(N<=1000)代表一共有N个队员
第二行输入N个数表示初始时的队伍所对应的每个人的身高(100<=身高<=300)(第一个输入的是队首,最后一个输入的是队尾)
输出描述:
输出教练所需要的最小操作步数
输入
2 183 185
输出
0
输入
3 173 186 166
输出
1
说明
一次操作将站在队尾身高为166的队员放在队首就形成了166 173 186的从低到高有序队伍
分析:比2018年福州大学第十五届程序设计竞赛D题简单,板子题。
1 /** 2 3 :;LaEaHKEEGpPXU7;, 4 .:75pKH11252U252XapZgRQgD6XJscLr;,. 5 :LXpRgGaX521JLw1JswJJsJs22XHPPEZEGDOMMRDOa7. 6 .r2EDDZEpZPZP6KpHX5SXH5XXa5KwaXaSX5UJ1c77sLs2GMQQ6r . 7 ,LpgOGpEZGZEZEpZKpHHU5wP5HEDgpXpHa2SSa5aSXULr7rrirrJXRBp; ;B 8 ,J6MRZH6EgEEZE6E6EZZPZXXwSSGQXr::aPpP5USUHaHaKa5Lvrr7ri;rLHBB2: Kc 9 rpQDOpPPOGGZOGOZG6GEOEOEDPPGBa. .PaSSUXSUUUaUSaKXKS177r7rrrirSBBR7 .O, 10 :UBQOKPK6ZOOOEDEO6GZE6EpEpDgDBR: UBpXHa5aSaUS5SUS5XapPHJc7rrv7rr7sgBBs .g. 11 ;gBMPXpO6GEOEOEOEGEOEE6EZEEDRGBB EB5pKSXpHKaHSX552S5aUHHEX17c7vr7777s5RBS: .R; 12 .sQBPXpDZOODOgODGOGgEDEOEOGgGgOOMB: LBKKSXSHa52aaKXHXKaa5aSaaHXSJLcL7vcc777JDBBg2;. Qi 13 ;2ggp2EDDOggGEDGgDDOgGGZDOOZOGg6gEBX vBZaHUKaaUXXXSXXKXpXHXH5wwaa52U1wssLsLJccv1UDQBQ67. O7 14 :ZZUU5PROOEOZOZGGOODZOGgODZOOgOggRgRB; ;:..R6XaKKpP6PGppKPHpHpPX5aU21UUa5Sw52UwUJJv77L77sSpQMDU; ;B5 15 ,SRJ7sSHGggEOZOEG6OODpOZgggOQQBBBBBQBBQ.,;;. LBOgOgDRDDZODMgQRgRDaa552a252UUa25w5UaU2sLvccs7r7sJZBBMr ,XQJ: 16 LQHr77J6RGOZDZOEGEDGgDRORQBBBQRDPU1Jscwa7.,::.:J7r;::::. ..,:;i7UOgRRRgDPH5SUSU52U2HHa1JJJLJLccLr71RBB, 7R2, 17 :RZv;77JSgGOZEODEDGOEggQBBBMS7;:,:,,.,.,.:7L;:,;.: ,: . ..... .:;rJU6GgGRggEZHPaKXX2S221Js1Lc7r:7QB. .XX: 18 7g1;;7rcXG6gpGDZGgZOOQBBQpr. ::::;:;:::Jr::sr;::;:.:vs,:::::::::::,, ,:7L5HGOggRgZUUU5wSUaJLc7r7BOiDr ... 19 .XX;;;irLHGKpZZZEKgDRBBB6i ,;;:;;;;r;;:s177:,;L7:;7:.rHi,:::::::::::::::::,. .,;7ZRQgO6KUUJsLwsJ7KBM. ..... 20 JZ:;rrrc5EPHp6XgpRBBBE; :i:;;;;;:;;;:c7::r7;,::::::::rv:,:::::::::::,:,:,:,,,, .;sORQRGX21wsXU: .... . 21 .Br;iir72EHPHZ6EgBBR7. ..;ii:;;;;;;;;;:71r::.:7, .::7;:;H;.::,:j::::::,:::::,,,::,,, ,7wEDRZBMr ....... 22 1D;:r;rwOPXPKH6BBX, .:;:;;;:::;:;;;;;::Ls,;ss..r. ,c77;sLU,:,:::,:::,:,:,:,,,:,,,:::. .:.rP:....... 23 D2:i;rJpKHXHXgg7 .,,::::;:::::;:;:;;:;SL7sS2, :. ::::,:U7.:::,:::,:,,,,,:,,.,,,.,:, ;L:. .. ... 24 :Qc;i7LGZPa6gBM, ...,,::::::::::::;;::;.JJ;ic: ;:::,v1,.:::;7,,,:,:,:,,,,.:,,,,.. :2wr. ....... 25 sRr:rrwZGgBQR7. .,,::::::::::::::;::;:::Hr:7i ,;;:::U: .,,,:r.,,:,:,:,,,:,,,..... 7K2:. .......... 26 OX:irsXgQZ:. .,,:::,,:::,::::::::;;;::r5;r7: :;;;:7L ..,.,;:,:,:,,,:,:,,,,...... .rU6w;.............. 27 .BJ71EK5;. .,,::,:,:,,,:,:,::::::::;:;.Ls;r7 :;:::s, ..,,,r:.:.,,,.:, .,..... . .;s5XJr,..,............. 28 1Mv::. .:,:,,,,,,,:::::::,;:::;:;::..J7;c: ,. ,rri:27 , .,:;. ,:,:,,:..,.... .rpPL;:.. ... ............. 29 ..7Ls: .,,,:,,,:,:,:::,:,:::::,:::::: .Srrr, .,:;;;::::..:7r;r1 .: :E:..,,:,...,,.., ..XBQ7, ................... .. 30 ,;7v7r7:, ,,,,:.,,,,,,:,,::,:,,.::.,:.,:, :Jrr; ,r7,:.. ,:::L: . .7RJ .,.:.,......,,:MBs ..............,........ 31 .:;vJs7i, ,,,., ..,,:,,,:,,,:,:.,rs,,.:,, ;J;c, .,::;; Lr.E: .,...,....:,:1Z: .........,.,...........:,. 32 .;,,:r7J1wv;,. ....,.:. .,.,,:,,,:,,::::,sS;.:::, cLrr. . .,. .,..: ;; r5 ........,,:;s7. ....,.,.,...........,.,.,,. 33 ,BBs::: . ........,.,,,,,.:,,,:,:,,.;s7r,,,,, cc7; ,.,,. .:7rrJGMPOEL1, ..... ,,:rSr, : ,.,.,.,.,.........,,,,,. .. 34 rZL. ....... ..,,,.,,,..,,,.,;,...7J:s: .. .wr7, ... .rJpQBBBBBBBQgKP77s .. .,7S2,,....,....,.,.,......,,.,. .:cX2 35 ;SH7, . . . .. .,.,.,.,,,...,..r, ::Ur;7L . .57;. .rPBBQBBBPws:;r::::.,:P. .;S5;,..,...,.,.,.,.... ..,,, ..,7HSJvr 36 r7r;: . ... ..........,...,.. 7L;,rS;;ivr . 1r: . .rZBBK7;.JL,::Jrs;.:;,:;J, .,;LDv..:.,...,.,.,.,...,.,,:,, ,7sKGwc77; 37 .:7L7:, . ,r,..,.,,,...,..:iLL 7s;r;cv: U7. :vi;:. .. :Er:::.Ls. . ,7::::vHEi ,:,,.,,,.,.,,,,,,::::, .:1QBKJJUsssc 38 .:rvw1JsL7;, ,;..........,.:ir :r .ELr77v:,. Pr .. . Ls ,w. rr.r:JPr. ::,..,,,.,,,,:,:::,:,..7XgRE52US25w1c 39 .:;7JRQpX: ; .........,i: .,J ;gri;7r : 1; .X: . ,v :aK1, ,,:.,,,.,,,,:::::,;::::cOBB6K55UXUX5XUw 40 ;J,XQB7,: . ...,: .:7Z.7Zi7;r: , v, :w:;,.,:::7LUsc:..:,:.:,,,,,:,:::::::,:;c5BBPS5wSUSUaUaUa2 41 J7 rEBBg..,. ..... . ,L1PLKr:,:;r;;::, :, :;SXsJU1XLLr....:,,,,,,::::,::::::,::LL,,rZXUJU25552aUUUU 42 JL .:sXBB:... ., . ,OH777;,rZRBBBQL ..r, ,:r7::r:,;;....:,,,,,,,,.::::;::;:::.7gL UK2UUS1aw2wU25J 43 U7 .r71BB; . :.. .. :QJ;.;1pBBBBBGRBRi i: . .w7. ..,,:,,,,,:,:,:::::::,.,2BR: .DSaUSUUS525w5U1 44 2r :7rJBQ7 .;. . KL::JGBBBgE6Hp6XMQ; . ... ,2s ,,,,:::::,:::::::,,.:sQQB2 ;DHa5U52S2U25USJ 45 a: :7;1BB2 .v, sL;LPQgDBPH6KPQBpGBG . ... .. aP:. .. ,::,:::::,,,,.;rSgBQDa; :gSSwSUUU525US2U 46 5; ;;r2QBB, .s: :a7:PBZ2,:BEaZPKgBZOgB, . ...:LEHri::,:.,,.,,,::rsXRBgGKEJi, 2GH252SUS5S11wH5 47 U: ;:rwDBBr .c, rB6r 167.,,RQPp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, .rLap2Jr ;712OO6ZggRDZXHXpKK2211LLLc7wgBa2PODRGE6OZgDgGDGD 60 7QB; ,Jc76DaZXOZgDPEBBX, :c1HEZ1c;:,.,:;cHDgQQggMZgGOZO6OEGpXsLLsJXHPOBBBc;vss5EMggZDODOgED6 61 LZJ::iwrrr72EPgXU5OBBBBBBBp7: .i5P6wL;, .:LS6DMgMgZKgEOPOGGDDGEXULvLSOBBBBBQBgDQDJ5rrr7JOQQDDZGEgDD 62 wp rR5, .HQRX7r72RQBBBBBQBMEK6Uc7sc7cHOU:, .:LHgOQg6ZOPZpZGGEDERZPwcr7LKDDaJr:. rBX;;:r:ir1DBQMgRgDp 63 7D,sw: , Z. .LgBBQBBOsJaQBBBBBBXrr. .:rwZBBQgROgDgDOERRMgROOScrLsPP5r, 7Qs,::::::rUgRgZOG6 64 ,Q57:r ,: ,r U: .;; .vL7L;r:UG7.:sr;JSgQBgDEZXXUSXpHa21svr7r7s2v:. iQK...:,:::;LLJJws 65 OBHs;. :;;,v H: :6X; rpL;7pSrrr7r;::,....,,:;iirrvvvr, :BBPs;;:,,,,::;:: 66 ::rPDEL:..7:c;7r pK .: :KL.:r:.. ..:icsS5sr:,. JgGgBQDOSJss77r 67 :r;::: , PH r, ,;5: ,::::;7Ls7Lc7;: ,:7JP17rJUs 68 .:J: :; .,:K6BQS7:.,.,. 69 :r7Ji;r7;::;;. 70 . **/ 71 72 #include <bits/stdc++.h> 73 using namespace std; 74 75 #define FF(a, b) for(int i = a; i < b; i++) 76 #define RR(a, b) for(int i = a; i > b; i++) 77 #define ME(a, b) memset(a, b, sizeof(a)) 78 #define SC(x) scanf("%d", &x) 79 #define PR(x) printf("%d\n", x) 80 #define INF 0x3f3f3f3f 81 #define MAX 1002 82 #define MOD 1000000007 83 #define E 2.71828182845 84 #define M 8 85 #define N 6 86 typedef long long LL; 87 const double PI = acos(-1.0); 88 typedef pair<int, int> Author; 89 vector<pair<string, int> > VP; 90 91 int main(void){ 92 #ifdef LOCAL 93 freopen("in.txt", "r", stdin); 94 freopen("out.txt", "w", stdout); 95 #endif 96 ios::sync_with_stdio(false); cin.tie(0); 97 int i, n, people[MAX], mi, ma, ans; 98 cin>>n;ans = mi = ma =0; 99 FF(0, n){ 100 cin>>people[i]; 101 if(people[i] < ma) mi = max(people[i], mi); 102 ma = max(ma, people[i]); 103 } 104 ma = 0; 105 FF(0, n){ 106 if(people[i] < mi || (people[i] == mi && ma > people[i])) ans++; 107 ma = max(ma, people[i]); 108 } 109 cout<<ans<<endl; 110 return EXIT_SUCCESS; 111 }
链接:https://www.nowcoder.com/acm/contest/121/K
来源:牛客网
空间限制:C/C++ 131072K,其他语言262144K
64bit IO Format: %lld
题目描述
柯怡最近开始沉迷赌博,比如跟别人赌这次陕西皇家女子学院举办的校赛里面,AK人数的奇偶;
而这种赌博显然柯怡稳赚不赔,因为她可以偷偷参加校赛,然后在最后一分钟观察AK的人数,如果她赌的是奇数而那时有偶数个人AK,她只要用这剩下的一分钟自己AK一次就可以让数量变回偶数了;
聪明的ddjing发现了老千柯怡的阴险套路,万般无奈的柯怡只好更改赌博的套路,这次她觉得跟ddjing玩猜数字;
这个游戏很简单,规则是,柯怡和ddjing在游戏开始前,先规定数字的范围是1到n,而柯怡则从这n个数里面选出一个x并默默记在心中,每次ddjing去猜一个数y,柯怡会告诉ddjing,他是猜大了(y>x)还是猜小了(y<x),亦或者是猜对了(y==x);
而赌注则是,每次ddjing去猜一个数y的时候,若他没有猜中,那么他就需要向柯怡赠送y套女装(因为这是柯怡的最爱),如果他猜中了,那柯怡将会穿着小裙裙来到比赛现场给大家发气球;
虽然柯怡允许每次游戏的时候,ddjing可以猜任意次,直到猜中为止,但这显然可以为柯怡提供出千的可能,比如说,柯怡心中所选之数是x1,而ddjing第一次就猜中了,然后柯怡就会马上变更她心中所选之数为x2,同时告诉ddjing他猜大了还是猜小了,但柯怡不会破坏游戏规则(比如说ddjing猜了5,柯怡告诉ddjing猜大了,那新的数就不能是小于等于5的数);
虽然ddjing知道这个游戏有很大的出千空间,但他知道,只要付出足够多的女装,就能稳定赢得最后的胜利;
但ddjing手头比较紧,他想知道,对于猜测1~n的游戏,在柯怡不断出千的情况下,他最少要准备多少套女装,才能保证一定能猜到最终结果;
输入描述:
第一行一个整数T(T<=100),代表数据组数;
对于每组数据,只有一行整数n(n<=300),代表游戏的数字范围;
输出描述:
对于每组数据,输出一个整数,代表ddjing至少需要准备的女装数目;
输入
3 1 2 3
输出
0 1 2
说明
当n=1时,ddjing只要猜1就能猜中,所以不用赠送女装;
当n=2时,ddjing柯怡猜1,下一次就肯定能猜中,所以只需要赠送一件女装就好;
当n=3时,ddjing只要猜2,下一次就肯定能猜中,只需要要赠送两件女装就好;
分析:恶心题目,太长了,一道DP,二维数组.没啥好讲的
1 /** 2 3 :;LaEaHKEEGpPXU7;, 4 .:75pKH11252U252XapZgRQgD6XJscLr;,. 5 :LXpRgGaX521JLw1JswJJsJs22XHPPEZEGDOMMRDOa7. 6 .r2EDDZEpZPZP6KpHX5SXH5XXa5KwaXaSX5UJ1c77sLs2GMQQ6r . 7 ,LpgOGpEZGZEZEpZKpHHU5wP5HEDgpXpHa2SSa5aSXULr7rrirrJXRBp; ;B 8 ,J6MRZH6EgEEZE6E6EZZPZXXwSSGQXr::aPpP5USUHaHaKa5Lvrr7ri;rLHBB2: Kc 9 rpQDOpPPOGGZOGOZG6GEOEOEDPPGBa. .PaSSUXSUUUaUSaKXKS177r7rrrirSBBR7 .O, 10 :UBQOKPK6ZOOOEDEO6GZE6EpEpDgDBR: UBpXHa5aSaUS5SUS5XapPHJc7rrv7rr7sgBBs .g. 11 ;gBMPXpO6GEOEOEOEGEOEE6EZEEDRGBB EB5pKSXpHKaHSX552S5aUHHEX17c7vr7777s5RBS: .R; 12 .sQBPXpDZOODOgODGOGgEDEOEOGgGgOOMB: LBKKSXSHa52aaKXHXKaa5aSaaHXSJLcL7vcc777JDBBg2;. Qi 13 ;2ggp2EDDOggGEDGgDDOgGGZDOOZOGg6gEBX vBZaHUKaaUXXXSXXKXpXHXH5wwaa52U1wssLsLJccv1UDQBQ67. O7 14 :ZZUU5PROOEOZOZGGOODZOGgODZOOgOggRgRB; ;:..R6XaKKpP6PGppKPHpHpPX5aU21UUa5Sw52UwUJJv77L77sSpQMDU; ;B5 15 ,SRJ7sSHGggEOZOEG6OODpOZgggOQQBBBBBQBBQ.,;;. LBOgOgDRDDZODMgQRgRDaa552a252UUa25w5UaU2sLvccs7r7sJZBBMr ,XQJ: 16 LQHr77J6RGOZDZOEGEDGgDRORQBBBQRDPU1Jscwa7.,::.:J7r;::::. ..,:;i7UOgRRRgDPH5SUSU52U2HHa1JJJLJLccLr71RBB, 7R2, 17 :RZv;77JSgGOZEODEDGOEggQBBBMS7;:,:,,.,.,.:7L;:,;.: ,: . ..... .:;rJU6GgGRggEZHPaKXX2S221Js1Lc7r:7QB. .XX: 18 7g1;;7rcXG6gpGDZGgZOOQBBQpr. ::::;:;:::Jr::sr;::;:.:vs,:::::::::::,, ,:7L5HGOggRgZUUU5wSUaJLc7r7BOiDr ... 19 .XX;;;irLHGKpZZZEKgDRBBB6i ,;;:;;;;r;;:s177:,;L7:;7:.rHi,:::::::::::::::::,. .,;7ZRQgO6KUUJsLwsJ7KBM. ..... 20 JZ:;rrrc5EPHp6XgpRBBBE; :i:;;;;;:;;;:c7::r7;,::::::::rv:,:::::::::::,:,:,:,,,, .;sORQRGX21wsXU: .... . 21 .Br;iir72EHPHZ6EgBBR7. ..;ii:;;;;;;;;;:71r::.:7, .::7;:;H;.::,:j::::::,:::::,,,::,,, ,7wEDRZBMr ....... 22 1D;:r;rwOPXPKH6BBX, .:;:;;;:::;:;;;;;::Ls,;ss..r. ,c77;sLU,:,:::,:::,:,:,:,,,:,,,:::. .:.rP:....... 23 D2:i;rJpKHXHXgg7 .,,::::;:::::;:;:;;:;SL7sS2, :. ::::,:U7.:::,:::,:,,,,,:,,.,,,.,:, ;L:. .. ... 24 :Qc;i7LGZPa6gBM, ...,,::::::::::::;;::;.JJ;ic: ;:::,v1,.:::;7,,,:,:,:,,,,.:,,,,.. :2wr. ....... 25 sRr:rrwZGgBQR7. .,,::::::::::::::;::;:::Hr:7i ,;;:::U: .,,,:r.,,:,:,:,,,:,,,..... 7K2:. .......... 26 OX:irsXgQZ:. .,,:::,,:::,::::::::;;;::r5;r7: :;;;:7L ..,.,;:,:,:,,,:,:,,,,...... .rU6w;.............. 27 .BJ71EK5;. .,,::,:,:,,,:,:,::::::::;:;.Ls;r7 :;:::s, ..,,,r:.:.,,,.:, .,..... . .;s5XJr,..,............. 28 1Mv::. .:,:,,,,,,,:::::::,;:::;:;::..J7;c: ,. ,rri:27 , .,:;. ,:,:,,:..,.... .rpPL;:.. ... ............. 29 ..7Ls: .,,,:,,,:,:,:::,:,:::::,:::::: .Srrr, .,:;;;::::..:7r;r1 .: :E:..,,:,...,,.., ..XBQ7, ................... .. 30 ,;7v7r7:, ,,,,:.,,,,,,:,,::,:,,.::.,:.,:, :Jrr; ,r7,:.. ,:::L: . .7RJ .,.:.,......,,:MBs ..............,........ 31 .:;vJs7i, ,,,., ..,,:,,,:,,,:,:.,rs,,.:,, ;J;c, .,::;; Lr.E: .,...,....:,:1Z: .........,.,...........:,. 32 .;,,:r7J1wv;,. ....,.:. .,.,,:,,,:,,::::,sS;.:::, cLrr. . .,. .,..: ;; r5 ........,,:;s7. ....,.,.,...........,.,.,,. 33 ,BBs::: . ........,.,,,,,.:,,,:,:,,.;s7r,,,,, cc7; ,.,,. .:7rrJGMPOEL1, ..... ,,:rSr, : ,.,.,.,.,.........,,,,,. .. 34 rZL. ....... ..,,,.,,,..,,,.,;,...7J:s: .. .wr7, ... .rJpQBBBBBBBQgKP77s .. .,7S2,,....,....,.,.,......,,.,. .:cX2 35 ;SH7, . . . .. .,.,.,.,,,...,..r, ::Ur;7L . .57;. .rPBBQBBBPws:;r::::.,:P. .;S5;,..,...,.,.,.,.... ..,,, ..,7HSJvr 36 r7r;: . ... ..........,...,.. 7L;,rS;;ivr . 1r: . .rZBBK7;.JL,::Jrs;.:;,:;J, .,;LDv..:.,...,.,.,.,...,.,,:,, ,7sKGwc77; 37 .:7L7:, . ,r,..,.,,,...,..:iLL 7s;r;cv: U7. :vi;:. .. :Er:::.Ls. . ,7::::vHEi ,:,,.,,,.,.,,,,,,::::, .:1QBKJJUsssc 38 .:rvw1JsL7;, ,;..........,.:ir :r .ELr77v:,. Pr .. . Ls ,w. rr.r:JPr. ::,..,,,.,,,,:,:::,:,..7XgRE52US25w1c 39 .:;7JRQpX: ; .........,i: .,J ;gri;7r : 1; .X: . ,v :aK1, ,,:.,,,.,,,,:::::,;::::cOBB6K55UXUX5XUw 40 ;J,XQB7,: . ...,: .:7Z.7Zi7;r: , v, :w:;,.,:::7LUsc:..:,:.:,,,,,:,:::::::,:;c5BBPS5wSUSUaUaUa2 41 J7 rEBBg..,. ..... . ,L1PLKr:,:;r;;::, :, :;SXsJU1XLLr....:,,,,,,::::,::::::,::LL,,rZXUJU25552aUUUU 42 JL .:sXBB:... ., . ,OH777;,rZRBBBQL ..r, ,:r7::r:,;;....:,,,,,,,,.::::;::;:::.7gL UK2UUS1aw2wU25J 43 U7 .r71BB; . :.. .. :QJ;.;1pBBBBBGRBRi i: . .w7. ..,,:,,,,,:,:,:::::::,.,2BR: .DSaUSUUS525w5U1 44 2r :7rJBQ7 .;. . KL::JGBBBgE6Hp6XMQ; . ... ,2s ,,,,:::::,:::::::,,.:sQQB2 ;DHa5U52S2U25USJ 45 a: :7;1BB2 .v, sL;LPQgDBPH6KPQBpGBG . ... .. aP:. .. ,::,:::::,,,,.;rSgBQDa; :gSSwSUUU525US2U 46 5; ;;r2QBB, .s: :a7:PBZ2,:BEaZPKgBZOgB, . ...:LEHri::,:.,,.,,,::rsXRBgGKEJi, 2GH252SUS5S11wH5 47 U: ;:rwDBBr .c, rB6r 167.,,RQPpEP6OpKEBc ., . : ::sS7;cKB6HHa1XOQRRQBRgEZDBH; .. ;RZUPSSU525USSpK2 48 s; ;::aBg, .; .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PEBBX, :c1HEZ1c;:,.,:;cHDgQQggMZgGOZO6OEGpXsLLsJXHPOBBBc;vss5EMggZDODOgED6 61 LZJ::iwrrr72EPgXU5OBBBBBBBp7: .i5P6wL;, .:LS6DMgMgZKgEOPOGGDDGEXULvLSOBBBBBQBgDQDJ5rrr7JOQQDDZGEgDD 62 wp rR5, .HQRX7r72RQBBBBBQBMEK6Uc7sc7cHOU:, .:LHgOQg6ZOPZpZGGEDERZPwcr7LKDDaJr:. rBX;;:r:ir1DBQMgRgDp 63 7D,sw: , Z. .LgBBQBBOsJaQBBBBBBXrr. .:rwZBBQgROgDgDOERRMgROOScrLsPP5r, 7Qs,::::::rUgRgZOG6 64 ,Q57:r ,: ,r U: .;; .vL7L;r:UG7.:sr;JSgQBgDEZXXUSXpHa21svr7r7s2v:. iQK...:,:::;LLJJws 65 OBHs;. :;;,v H: :6X; rpL;7pSrrr7r;::,....,,:;iirrvvvr, :BBPs;;:,,,,::;:: 66 ::rPDEL:..7:c;7r pK .: :KL.:r:.. ..:icsS5sr:,. JgGgBQDOSJss77r 67 :r;::: , PH r, ,;5: ,::::;7Ls7Lc7;: ,:7JP17rJUs 68 .:J: :; .,:K6BQS7:.,.,. 69 :r7Ji;r7;::;;. 70 . **/ 71 72 #include <bits/stdc++.h> 73 using namespace std; 74 75 #define FFI(a, b) for(int i = a; i < b; i++) 76 #define FFJ(a, b) for(int j = a; j < b; j++) 77 #define RR(a, b) for(int i = a; i > b; i++) 78 #define ME(a, b) memset(a, b, sizeof(a)) 79 #define SC(x) scanf("%d", &x) 80 #define PR(x) printf("%d\n", x) 81 #define INF 0x3f3f3f3f 82 #define MAX 330 83 #define MOD 1000000007 84 #define E 2.71828182845 85 #define M 8 86 #define N 6 87 typedef long long LL; 88 const double PI = acos(-1.0); 89 typedef pair<int, int> Author; 90 vector<pair<string, int> > VP; 91 int fun[MAX][MAX]; 92 93 void Init(){ 94 ME(fun, 125); 95 FFI(0, 303) FFJ(0, 303) if(i >= j) fun[i][j] = 0; 96 FFI(2, 301){ 97 FFJ(1, 301){ 98 int be = j, en = j + i - 1; 99 if(en > 300) break; 100 for(int k = be; k <= en; k++) fun[be][en] = min(fun[be][en], k + max(fun[be][k - 1], fun[k + 1][en])); 101 } 102 } 103 } 104 105 int main(void){ 106 #ifdef LOCAL 107 freopen("in.txt", "r", stdin); 108 freopen("out.txt", "w", stdout); 109 #endif 110 ios::sync_with_stdio(false); cin.tie(0); 111 int T, n;Init(); 112 113 cin>>T; 114 while(T--){ 115 cin>>n; 116 cout<<fun[1][n]<<endl; 117 } 118 return EXIT_SUCCESS; 119 }