首页 > 代码库 > BZOJ3758 数数
BZOJ3758 数数
首先我们看对于一个数怎么判断。
方法是,暴力判断。。。←_←(不要骗我。。。)
首先看各位数字之和,如果是奇数就不是"优美"的。
否则用dp判断,我们可以状压一下,直接记一个long long大小的数叫f,则f |= (f << num),其中num表示一位数。
时间复杂度是log(x),其中x是要判断的数字。
很慢?貌似是的说。。。于是,分块打表大法好!!!
我们设一个块大小10^6,总共10^3个块(要考虑到可能会编译超时的问题),于是直接求出来每个块之前的ans,然后直接暴力块内的ans就可以了。
1 /************************************************************** 2 Problem: 3758 3 User: rausen 4 Language: C++ 5 Result: Accepted 6 Time:652 ms 7 Memory:808 kb 8 ****************************************************************/ 9 10 #include <cstdio>11 12 using namespace std;13 typedef long long ll;14 const int sz = 1000000;15 const int T[] = {0, 376413, 832547, 1288828, 1744956, 2196800, 2647716, 3090920, 3526440, 3951372, 4366880, 4823015, 5304766, 5797144, 6290672, 6782004, 7272530, 7758910, 8238396, 8710536, 9182258, 9638539, 10130918, 10610575, 11103529, 11590745, 12080513, 12565094, 13045216, 13523103, 13996047, 14452175, 14945703, 15438658, 15913605, 16403907, 16892727, 17371943, 17858307, 18339125, 18810719, 19262563, 19753895, 20241111, 20731414, 21199399, 21684697, 22170473, 22655525, 23128982, 23601310, 24052226, 24542752, 25032520, 25521340, 26006639, 26480512, 26967738, 27450344, 27929454, 28401296, 28844500, 29330880, 29815461, 30294677, 30780453, 31267680, 31727883, 32207445, 32681531, 33151141, 33586661, 34066147, 34546269, 35032633, 35517685, 36000291, 36479854, 36928875, 37398605, 37865237, 38290169, 38762309, 39240196, 39721014, 40194471, 40673581, 41147667, 41617398, 42050819, 42514127, 42929635, 43401357, 43874301, 44345895, 44818223, 45290065, 45759675, 46226307, 46689616, 47111407, 47567542, 48049293, 48541671, 49035199, 49526531, 50017057, 50503437, 50982923, 51455063, 51926786, 52408537, 52900916, 53398017, 53897101, 54395976, 54894264, 55390376, 55882154, 56370124, 56858336, 57350715, 57847816, 58346901, 58846682, 59346650, 59846494, 60345546, 60842736, 61337762, 61832643, 62326171, 62825256, 63325037, 63822618, 64321881, 64821477, 65319367, 65818159, 66315614, 66811192, 67302524, 67801399, 68301368, 68800631, 69295186, 69792675, 70292149, 70790949, 71286703, 71781713, 72272239, 72770527, 73270371, 73769968, 74267457, 74763402, 75261351, 75759527, 76256605, 76751555, 77237935, 77734047, 78233099, 78730989, 79230464, 79728413, 80220834, 80714563, 81209373, 81704149, 82183635, 82675413, 83172603, 83671395, 84170195, 84668372, 85162101, 85646750, 86134011, 86626601, 87098741, 87586711, 88081737, 88579192, 89074946, 89572024, 90066835, 90554096, 91029271, 91513942, 91985664, 92473876, 92968757, 93464335, 93959345, 94454295, 94949071, 95441662, 95926333, 96400455, 96856736, 97349115, 97828772, 98321726, 98808942, 99298710, 99783291, 100263413, 100741300, 101214244, 101706623, 102203724, 102702809, 103202590, 103702558, 104202402, 104701454, 105198644, 105693670, 106188552, 106668209, 107167293, 107654509, 108153408, 108643571, 109140447, 109631936, 110124934, 110615086, 111104170, 111597125, 112096906, 112595804, 113093027, 113592810, 114091415, 114589181, 115087418, 115585176, 116080738, 116567954, 117067923, 117558086, 118057868, 118549357, 119048442, 119540443, 120037757, 120529913, 121025141, 121514909, 122014753, 122511630, 123010235, 123509319, 124005151, 124504320, 124999107, 125496723, 125991518, 126476099, 126975151, 127466640, 127964407, 128456408, 128955576, 129444361, 129941988, 130432181, 130927549, 131407671, 131904861, 132397859, 132896096, 133393411, 133888198, 134385824, 134870790, 135365761, 135853348, 136331235, 136826261, 137316413, 137814171, 138306327, 138803944, 139294137, 139789107, 140268613, 140761869, 141234813, 141729694, 142218778, 142714340, 143209568, 143704363, 144199732, 144687319, 145180575, 145654892, 146111020, 146604548, 147097503, 147572450, 148062752, 148551572, 149030788, 149517152, 149997970, 150469564, 150963092, 151462177, 151961958, 152459539, 152958802, 153458398, 153956288, 154455080, 154952535, 155448113, 155941068, 156440849, 156939747, 157436970, 157936753, 158435358, 158933124, 159431361, 159929119, 160424682, 160899629, 161397209, 161894432, 162373648, 162870479, 163366196, 163847035, 164342307, 164834856, 165316242, 165806545, 166305808, 166805590, 167302421, 167797533, 168296439, 168794206, 169291181, 169787227, 170282583, 170771403, 171271000, 171769605, 172265321, 172764227, 173259685, 173756939, 174255102, 174749455, 175244787, 175724003, 176221893, 176719660, 177200499, 177698265, 178195519, 178676905, 179174053, 179669962, 180151503, 180637867, 181136659, 181634896, 182130169, 182627144, 183125306, 183622454, 184112942, 184610046, 185104838, 185585656, 186083111, 186580869, 187073418, 187569465, 188063818, 188559726, 189056830, 189540680, 190034891, 190506485, 191002063, 191497625, 191979011, 192474367, 192969700, 193451241, 193946033, 194440244, 194913068, 195364912, 195856244, 196343460, 196833763, 197301748, 197787046, 198272822, 198757874, 199231331, 199703659, 200194991, 200693866, 201193835, 201693098, 202187653, 202685142, 203184616, 203683416, 204179170, 204674180, 205161396, 205661365, 206151528, 206651310, 207142799, 207641884, 208133885, 208631199, 209123355, 209618583, 210108886, 210608149, 211107931, 211604762, 212099874, 212598780, 213096547, 213593522, 214089568, 214584925, 215052910, 215547464, 216038953, 216534065, 217007522, 217499718, 217990901, 218484410, 218959905, 219446727, 219932026, 220429515, 220928599, 221427505, 221919701, 222413231, 222911993, 223409872, 223904583, 224393574, 224879350, 225378825, 225870826, 226368592, 226859775, 227358537, 227847477, 228346119, 228838089, 229333643, 229818695, 230317495, 230814810, 231311785, 231805293, 232303172, 232801814, 233291625, 233787283, 234281777, 234755234, 235250988, 235743144, 236239191, 236714686, 237209396, 237701366, 238197024, 238673284, 239165608, 239637936, 240132946, 240628174, 241123530, 241610353, 242099344, 242594898, 243089392, 243581716, 244056062, 244506978, 244997504, 245487272, 245976092, 246461391, 246935264, 247422490, 247905096, 248384206, 248856048, 249346574, 249844862, 250344706, 250844303, 251341792, 251837737, 252335686, 252833862, 253330940, 253825890, 254315658, 254815502, 255312379, 255810984, 256310068, 256805900, 257305069, 257799856, 258297472, 258792267, 259281087, 259780684, 260279289, 260775005, 261273911, 261769369, 262266623, 262764786, 263259139, 263754471, 264239770, 264737259, 265236343, 265735249, 266227445, 266720975, 267219737, 267717616, 268212327, 268701319, 269175192, 269671136, 270166968, 270662426, 271155956, 271637394, 272132980, 272626656, 273118401, 273606213, 274093440, 274591389, 275090557, 275587811, 276086573, 276582159, 277074753, 277572087, 278069041, 278564272, 279046878, 279545055, 280039842, 280538004, 281035883, 281529559, 282026893, 282513143, 283009664, 283502662, 283981772, 284478850, 284976467, 285470820, 285965530, 286457275, 286954229, 287450750, 287934208, 288427696, 288899538, 289394488, 289889283, 290384616, 290873607, 291361419, 291856650, 292349648, 292843136, 293317366, 293760570, 294246950, 294731531, 295210747, 295696523, 296183750, 296643953, 297123515, 297597601, 298067211, 298553591, 299049703, 299548755, 300046645, 300546120, 301044069, 301536490, 302030219, 302525029, 303019805, 303504386, 304003438, 304494927, 304992694, 305484695, 305983863, 306472648, 306970275, 307460468, 307955836, 308435052, 308932942, 309430709, 309911548, 310409314, 310906568, 311387954, 311885102, 312381011, 312862552, 313348328, 313847803, 314339804, 314837570, 315328753, 315827515, 316316455, 316815097, 317307067, 317802621, 318289848, 318787797, 319286965, 319784219, 320282981, 320778567, 321271161, 321768495, 322265449, 322760681, 323220884, 323713304, 324202089, 324683475, 325172415, 325665009, 326128508, 326618472, 327104745, 327585453, 328065016, 328558745, 329056371, 329553519, 330052161, 330549495, 331039459, 331524705, 332017239, 332510934, 332985020, 333479831, 333970024, 334465932, 334957902, 335454856, 335941129, 336433663, 336912903, 337405293, 337874903, 338369679, 338865048, 339346589, 339842143, 340337374, 340818082, 341311777, 341804167, 342276694, 342712214, 343191700, 343671822, 344158186, 344643238, 345125844, 345605407, 346054428, 346524158, 346990790, 347470276, 347962054, 348459244, 348958036, 349456836, 349955013, 350448742, 350933391, 351420652, 351913242, 352393364, 352890554, 353383552, 353881789, 354379104, 354873891, 355371517, 355856483, 356351454, 356839041, 357325405, 357824197, 358322434, 358817707, 359314682, 359812844, 360309992, 360800480, 361297584, 361792376, 362277428, 362776228, 363273543, 363770518, 364264026, 364761905, 365260547, 365750358, 366246016, 366740510, 367223116, 367721293, 368216080, 368714242, 369212121, 369705797, 370203131, 370689381, 371185902, 371678900, 372158463, 372652192, 373149818, 373646966, 374145608, 374642942, 375132906, 375618152, 376110686, 376604382, 377053403, 377538051, 378023017, 378513505, 379003316, 379489566, 379974812, 380427196, 380908305, 381388631, 381858362, 382345623, 382840593, 383337697, 383833355, 384329876, 384822410, 385303519, 385778157, 386266143, 386732775, 387225366, 387712953, 388207745, 388702239, 389195237, 389688932, 390169258, 390657244, 391130374, 391555306, 392027446, 392505333, 392986151, 393459608, 393938718, 394412804, 394882535, 395315956, 395779264, 396251404, 396739374, 397234400, 397731855, 398227609, 398724687, 399219498, 399706759, 400181934, 400666605, 401144492, 401639518, 402129670, 402627428, 403119584, 403617201, 404107394, 404602364, 405081870, 405575126, 406055944, 406553399, 407051157, 407543706, 408039753, 408534106, 409030014, 409527118, 410010968, 410505179, 410978636, 411474390, 411966546, 412462593, 412938088, 413432798, 413924768, 414420426, 414896686, 415389010, 415868120, 416365198, 416862815, 417357168, 417851878, 418343623, 418840577, 419337098, 419820556, 420314044, 420788130, 421282941, 421773134, 422269042, 422761012, 423257966, 423744239, 424236773, 424716013, 425208403, 425678134, 426165395, 426660365, 427157469, 427653127, 428149648, 428642182, 429123291, 429597929, 430085916, 430519337, 430994511, 431474017, 431957867, 432434127, 432917585, 433396825, 433871463, 434306086, 434779290, 435242599, 435727270, 436220526, 436714737, 437207061, 437700549, 438192939, 438680925, 439154129, 439626259, 440041767, 440513489, 440986433, 441458027, 441930355, 442402197, 442871807, 443338439, 443801748, 444223539, 444695261, 445183473, 445678354, 446173932, 446668942, 447163892, 447658668, 448151259, 448635930, 449110052, 449582996, 450077877, 450566961, 451062523, 451557751, 452052546, 452547915, 453035502, 453528758, 454003075, 454474669, 454970247, 455465809, 455947195, 456442551, 456937884, 457419425, 457914217, 458408428, 458881252, 459353580, 459848590, 460343818, 460839174, 461325997, 461814988, 462310542, 462805036, 463297360, 463771706, 464243548, 464738498, 465233293, 465728626, 466217617, 466705429, 467200660, 467693658, 468187146, 468661376, 469130986, 469625762, 470121131, 470602672, 471098226, 471593457, 472074165, 472567860, 473060250, 473532777, 473999409, 474492000, 474979587, 475474379, 475968873, 476461871, 476955566, 477435892, 477923878, 478397008, 478860317, 479344988, 479838244, 480332455, 480824779, 481318267, 481810657, 482298643, 482771847, 483243978, 483665769, 484139891, 484614208, 485087032, 485561378, 486035608, 486508135, 486981265, 487453395, 487875963};16 inline int check(int x) {17 int i = x, tot = 0;18 while (i)19 tot += i % 10, i /= 10;20 if (tot & 1) return 0;21 ll f = 1;22 tot >>= 1, i = x;23 while (i)24 f |= (f << i % 10), i /= 10;25 return (f >> tot) & 1;26 }27 28 int calc(int x) {29 int i, res = T[x / sz];30 for (i = (x / sz) * sz + 1; i <= x; ++i)31 res += check(i);32 return res;33 }34 35 int main() {36 int a, b, x;37 x = scanf("%d%d", &a, &b);38 printf("%d\n", calc(b) - calc(a - 1));39 }
BZOJ3758 数数
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。