2021牛客暑期多校训练营1 部分题解

补一波牛客多校的题解~

A

这题我的想法是记忆化搜索,如果当前状态能够转移到必败态,那么当前状态就是必胜态。

直接枚举的话复杂度是 \(O(N^3logN)\) ,所以我打了个表,将所有必败态存了下来。

下面是 generator ,因为打表程序已经被我丢掉了所以就贴截图了(悲

image

然后这是 AC 代码。

#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define debug(x) cerr << #x << ": " << x << endl
#define pb(a) push_back(a)
#define set0(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define dwn(i,a,b) for(int i=(a);i>=(b);i--)
#define ceil(a,b) (a+(b-1))/b
#define INF 0x3f3f3f3f
#define ll_INF 0x7f7f7f7f7f7f7f7f
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;

inline void read(int &x) {
    int s=0;x=1;
    char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-')x=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+ch-'0',ch=getchar();
    x*=s;
}

set<PII> buf={
	{2,3},{5,7},{9,12},{11,15},{14,20},{17,22},{19,33},{24,32},{26,35},{28,58},{29,40},{31,38},{37,53},{42,52},{44,75},{45,60},{47,65},{49,70},{50,62},{55,68},{57,79},{64,87},{67,86},{72,92},{74,99},{77,101},{81,174},{82,118},{83,110},{85,113},{89,123},{90,116},{94,129},{95,127},{97,126},{103,136},{105,199},{106,146},{108,145},{112,166},{115,246},{120,161},{122,160},{125,164},{131,309},{132,182},{133,177},{135,198},{138,180},{139,156},{141,239},{142,190},{143,186},{148,203},{149,195},{151,340},{152,197},{154,232},{158,218},{163,229},{168,215},{170,286},{171,228},{172,224},{176,350},{179,298},{184,253},{185,236},{188,268},{189,259},{192,241},{194,256},{201,266},{205,281},{207,274},{208,264},{210,271},{212,322},{213,317},{214,278},{217,289},{220,327},{221,280},{223,315},{226,301},{231,332},{234,307},{238,372},{243,391},{244,325},{245,313},{248,306},{250,321},{252,305},{255,339},{258,565},{261,346},{263,359},{270,375},{273,521},{276,358},{283,370},{285,362},{288,379},{291,456},{293,367},{295,390},{296,386},{300,432},{303,415},{311,464},{312,411},{319,408},{324,501},{329,435},{331,702},{334,454},{336,545},{337,489},{338,449},{342,496},{343,446},{345,445},{348,558},{349,467},{352,461},{354,590},{355,577},{356,532},{357,479},{361,478},{364,494},{366,527},{369,520},{374,509},{377,505},{381,639},{382,553},{384,470},{388,485},{393,518},{395,474},{397,511},{399,487},{400,483},{402,588},{404,601},{405,531},{407,530},{410,568},{413,537},{417,586},{419,557},{420,541},{421,529},{423,525},{425,580},{427,560},{429,719},{430,624},{431,570},{434,549},{437,574},{439,603},{440,600},{442,683},{443,556},{448,614},{451,871},{452,651},{453,620},{458,772},{459,671},{460,596},{463,661},{466,666},{469,610},{472,761},{473,632},{476,760},{477,691},{481,660},{491,726},{492,635},{498,673},{499,646},{503,653},{504,649},{507,788},{508,648},{513,776},{514,716},{515,664},{516,658},{523,740},{534,893},{535,855},{539,752},{540,735},{543,723},{547,825},{548,800},{551,697},{555,711},{562,1202},{563,771},{564,693},{567,737},{572,744},{576,766},{579,780},{582,986},{583,768},{585,748},{592,877},{593,811},{594,805},{595,722},{598,1599},{599,828},{605,866},{606,845},{607,810},{609,849},{612,842},{616,831},{617,822},{619,787},{622,818},{626,799},{628,785},{630,836},{634,778},{637,879},{641,886},{643,899},{644,827},{655,1046},{656,918},{657,876},{663,870},{668,989},{669,929},{675,985},{676,857},{678,912},{679,904},{680,896},{682,1107},{685,869},{687,964},{689,920},{695,883},{699,946},{700,937},{704,948},{706,910},{708,957},{710,892},{713,996},{714,935},{718,969},{721,976},{725,1358},{728,1010},{730,917},{732,924},{734,1167},{739,1062},{742,1036},{743,1007},{746,1065},{747,1000},{750,982},{751,944},{754,1020},{756,1013},{757,995},{759,1854},{763,991},{765,1038},{770,1150},{774,1017},{782,1032},{784,1085},{790,1082},{791,1061},{793,1090},{794,956},{796,1029},{797,1023},{802,1777},{803,1072},{807,1081},{808,1079},{813,1118},{814,1117},{815,1110},{816,1040},{820,1131},{824,1070},{830,1098},{833,1053},{835,1122},{838,1201},{839,1165},{841,1322},{844,1241},{847,1225},{848,1120},{851,1190},{852,1106},{853,1076},{859,1145},{861,1206},{862,1180},{863,1130},{864,1055},{868,1156},{873,1384},{874,1212},{875,1102},{881,1194},{882,1175},{885,1164},{888,1192},{890,1186},{895,1285},{898,1227},{901,2018},{902,1211},{906,1208},{908,1261},{909,1231},{914,1245},{915,1214},{922,1394},{923,1269},{926,1363},{927,1243},{931,1274},{933,1307},{939,1405},{940,1268},{942,1381},{943,1219},{950,1265},{952,1314},{954,1254},{959,1311},{960,1297},{962,1420},{963,1295},{966,1390},{967,1279},{971,1337},{972,1302},{973,1248},{975,3859},{978,1284},{980,1547},{981,1348},{984,1317},{988,1451},{993,1378},{994,1329},{998,1812},{999,1372},{1002,1336},{1004,1461},{1005,1400},{1006,1346},{1009,1366},{1012,1361},{1015,1465},{1016,1432},{1019,1419},{1022,1477},{1025,1376},{1027,1292},{1031,1633},{1034,1389},{1035,1371},{1042,1527},{1043,1334},{1045,1387},{1048,1458},{1050,2369},{1051,1331},{1057,1695},{1058,1414},{1060,1408},{1064,1446},{1067,1543},{1068,1521},{1069,1413},{1074,1514},{1075,1492},{1078,1428},{1084,1687},{1087,1499},{1088,1457},{1089,1397},{1092,1468},{1094,1455},{1096,1443},{1100,1425},{1104,1464},{1109,1481},{1112,1606},{1113,1539},{1115,1758},{1116,1484},{1124,1510},{1125,1449},{1127,1626},{1129,1516},{1133,1575},{1134,1509},{1136,1532},{1137,1502},{1139,1537},{1140,1438},{1142,1563},{1143,1470},{1144,1403},{1147,2604},{1148,1674},{1149,1581},{1152,1541},{1153,1536},{1155,1534},{1158,1569},{1159,1529},{1161,1525},{1163,1592},{1169,1561},{1171,1612},{1173,1619},{1174,1491},{1177,2077},{1178,1577},{1182,2623},{1183,1560},{1185,1665},{1188,1611},{1196,1906},{1197,1590},{1199,1653},{1200,1636},{1204,1679},{1210,2455},{1216,1736},{1217,1625},{1221,1640},{1223,1929},{1224,1717},{1229,1617},{1233,1730},{1235,1678},{1236,1651},{1237,1643},{1238,1622},{1239,1580},{1247,1605},{1250,1820},{1251,1746},{1253,1721},{1256,2215},{1257,1799},{1258,1661},{1260,1708},{1263,1769},{1264,1713},{1267,1795},{1271,2004},{1272,1707},{1276,1694},{1278,1692},{1281,1682},{1283,1664},{1287,1882},{1289,1702},{1290,1684},{1294,1866},{1299,1845},{1300,1756},{1301,1710},{1304,1825},{1305,1765},{1309,1832},{1310,1774},{1313,2810},{1316,1767},{1319,1811},{1320,1754},{1324,2388},{1325,1787},{1327,1729},{1333,2140},{1339,1822},{1340,1785},{1342,1850},{1343,1802},{1344,1782},{1350,2840},{1351,2288},{1352,1842},{1354,1831},{1356,1888},{1357,1762},{1360,1838},{1365,1879},{1368,1884},{1369,1878},{1370,1859},{1374,2836},{1375,2036},{1380,1824},{1383,1919},{1386,1904},{1392,1863},{1396,1901},{1399,1978},{1402,1966},{1407,1914},{1410,1877},{1412,2042},{1416,1847},{1418,1772},{1422,1935},{1424,2040},{1427,2981},{1430,1837},{1434,1975},{1436,1953},{1437,1923},{1440,2051},{1441,1994},{1442,1869},{1445,2209},{1448,1949},{1453,2007},{1460,1947},{1463,2011},{1467,2230},{1472,1942},{1474,2205},{1475,1922},{1479,2031},{1480,1941},{1483,2134},{1486,2657},{1487,2026},{1489,2107},{1490,2030},{1494,1992},{1495,1964},{1497,1997},{1501,2098},{1504,1986},{1505,1970},{1507,2003},{1508,1981},{1512,2191},{1513,2088},{1518,2096},{1520,1972},{1523,3303},{1524,2059},{1531,2076},{1545,2390},{1546,2056},{1549,2421},{1550,2094},{1551,2070},{1553,2129},{1554,2033},{1555,2029},{1557,2116},{1559,3159},{1565,2067},{1566,2050},{1568,2105},{1571,2001},{1573,2256},{1574,2161},{1579,2103},{1583,2338},{1584,2180},{1586,2148},{1587,2137},{1588,2100},{1589,2080},{1594,2168},{1596,3385},{1597,2085},{1601,2195},{1603,2152},{1604,2142},{1608,2329},{1609,2281},{1610,2203},{1614,2198},{1616,2176},{1621,2184},{1624,2669},{1628,2194},{1630,2145},{1632,3560},{1635,2302},{1638,2229},{1642,2224},{1645,2954},{1646,2298},{1647,2276},{1648,2255},{1650,2239},{1655,2310},{1657,2182},{1659,2217},{1663,2193},{1667,2640},{1668,2366},{1669,2356},{1670,2174},{1672,2293},{1673,2202},{1676,2347},{1681,2271},{1686,3335},{1689,2437},{1690,2237},{1691,2222},{1697,4572},{1698,2297},{1699,2268},{1700,2261},{1701,2234},{1704,2132},{1706,2287},{1712,2246},{1715,2607},{1716,2439},{1719,2341},{1723,2368},{1724,2322},{1726,2335},{1728,2283},{1732,2376},{1734,3235},{1735,2495},{1738,2427},{1740,2490},{1741,2163},{1743,2362},{1744,2350},{1745,2318},{1748,3156},{1749,2453},{1751,2254},{1753,2345},{1760,2426},{1761,2317},{1764,2406},{1771,2538},{1776,2381},{1779,2557},{1780,2411},{1781,2385},{1784,2449},{1789,2402},{1790,2358},{1792,2393},{1794,2404},{1797,2910},{1798,2375},{1801,3252},{1804,2516},{1805,2332},{1807,2435},{1808,2420},{1810,2473},{1814,2365},{1816,3712},{1817,2400},{1818,2398},{1827,2957},{1828,2469},{1830,2415},{1834,2634},{1835,2459},{1840,2751},{1841,2523},{1844,2493},{1849,2485},{1852,2879},{1856,2720},{1857,2551},{1858,2444},{1861,3273},{1862,2613},{1865,2513},{1868,3991},{1871,2505},{1873,2395},{1875,2830},{1876,2502},{1881,2576},{1886,2773},{1890,2525},{1891,2462},{1893,2743},{1894,2572},{1896,2709},{1897,2511},{1899,2600},{1900,2515},{1903,2567},{1908,4079},{1909,2509},{1911,2564},{1913,2530},{1916,2592},{1917,2575},{1921,2708},{1925,2550},{1926,2549},{1927,2492},{1931,4030},{1932,2700},{1933,2665},{1934,2642},{1937,2597},{1938,2570},{1940,2548},{1944,2661},{1951,2789},{1952,2689},{1955,2675},{1956,2647},{1958,2632},{1959,2616},{1961,2931},{1963,2761},{1968,2953},{1969,2691},{1974,2611},{1977,2673},{1980,2986},{1983,2645},{1985,2738},{1988,2687},{1989,2546},{1991,2707},{1996,2780},{1999,2704},{2006,3078},{2009,2682},{2013,2556},{2015,2729},{2016,2684},{2020,2938},{2021,2702},{2023,2779},{2025,2671},{2028,3048},{2035,4593},{2038,2832},{2039,2627},{2044,3121},{2045,2785},{2047,2749},{2048,2668},{2053,4805},{2055,2747},{2058,2733},{2061,3037},{2062,2759},{2064,2806},{2066,2754},{2069,2902},{2072,2816},{2074,2809},{2079,2850},{2082,3254},{2083,3207},{2084,2856},{2087,2798},{2090,2956},{2091,2768},{2092,2746},{2102,2891},{2109,3138},{2110,2864},{2111,2758},{2113,2883},{2114,2804},{2118,4706},{2119,2788},{2121,2925},{2122,2921},{2124,2899},{2125,2834},{2126,2826},{2128,2778},{2131,3334},{2139,2882},{2144,3811},{2147,2881},{2150,3039},{2151,2869},{2154,2970},{2155,2862},{2157,4055},{2158,2814},{2160,2919},{2165,2792},{2167,2943},{2170,2873},{2172,3020},{2173,2843},{2178,2927},{2179,2917},{2186,3478},{2187,2846},{2189,2985},{2197,3244},{2200,2915},{2207,3067},{2208,3036},{2211,3908},{2212,2905},{2214,3024},{2219,2946},{2221,3261},{2226,3229},{2227,3015},{2228,2997},{2232,3064},{2233,2972},{2236,2960},{2241,3061},{2242,3007},{2244,2974},{2248,3119},{2249,3001},{2251,3148},{2252,3089},{2253,3026},{2258,3110},{2259,3099},{2260,2979},{2263,3433},{2265,2993},{2267,3046},{2270,3006},{2273,3338},{2274,3032},{2275,3004},{2279,3589},{2280,3097},{2285,3031},{2290,3172},{2292,3333},{2295,3057},{2300,3193},{2301,3084},{2304,3460},{2305,3163},{2306,3125},{2308,3130},{2312,3118},{2314,3425},{2316,3128},{2320,3218},{2321,3082},{2324,3117},{2326,3250},{2328,3012},{2331,3113},{2334,3202},{2340,3570},{2343,3396},{2344,3145},{2349,3763},{2352,3519},{2353,3197},{2354,3101},{2360,3423},{2361,3217},{2364,4038},{2371,3585},{2372,3289},{2373,3247},{2374,3177},{2378,3731},{2379,3213},{2380,3106},{2383,3201},{2384,3169},{2387,3314},{2392,3182},{2397,3810},{2408,3359},{2409,3190},{2413,3179},{2417,3103},{2419,3512},{2423,3258},{2425,4507},{2429,3393},{2431,3116},{2433,3341},{2434,3225},{2441,3327},{2442,3317},{2443,3302},{2446,3269},{2448,4240},{2451,3281},{2452,3232},{2457,3351},{2461,3552},{2465,3206},{2467,3413},{2472,3246},{2475,3299},{2477,3864},{2478,3598},{2479,3287},{2481,3500},{2482,3345},{2484,3286},{2487,3498},{2488,3297},{2489,3294},{2497,4154},{2498,3495},{2499,3325},{2501,3384},{2504,3941},{2507,3358},{2508,3355},{2518,3441},{2519,3381},{2520,3374},{2521,3350},{2527,3471},{2529,3368},{2532,3412},{2533,3379},{2535,3534},{2537,3323},{2540,3838},{2541,3693},{2542,3544},{2543,3488},{2544,3405},{2553,3924},{2554,3395},{2555,3391},{2559,3592},{2560,3538},{2561,3241},{2563,3510},{2566,3502},{2569,3422},{2574,3699},{2578,3536},{2579,3467},{2580,3459},{2581,3454},{2582,3377},{2584,3684},{2585,3475},{2586,3343},{2587,3312},{2590,3722},{2594,3409},{2595,3372},{2599,3466},{2602,3558},{2606,3518},{2609,3464},{2615,4125},{2618,3628},{2619,3605},{2620,3601},{2621,3525},{2625,3739},{2626,3418},{2629,3578},{2630,3508},{2636,3667},{2637,3480},{2638,3463},{2644,3621},{2649,4089},{2650,3671},{2651,3547},{2652,3449},{2654,3367},{2656,3584},{2659,3569},{2663,4619},{2664,3506},{2667,3772},{2677,3748},{2678,3720},{2679,3658},{2680,3529},{2693,4018},{2694,3614},{2696,3565},{2698,3844},{2699,3638},{2706,3640},{2711,3977},{2712,3619},{2714,4162},{2715,3665},{2717,3643},{2718,3549},{2722,4815},{2723,3600},{2725,4479},{2726,3635},{2728,3814},{2731,3852},{2732,3727},{2735,3759},{2736,3689},{2737,3651},{2740,3832},{2741,3676},{2742,3647},{2745,3898},{2753,3917},{2756,3719},{2757,3673},{2763,4052},{2765,3698},{2767,3825},{2770,3974},{2771,3709},{2775,3705},{2777,4012},{2782,3681},{2784,3890},{2787,4608},{2791,3656},{2794,3862},{2795,3714},{2797,3957},{2800,3762},{2801,3733},{2802,3704},{2808,3769},{2812,3848},{2813,3787},{2818,3743},{2820,3854},{2823,3771},{2825,3756},{2828,4075},{2829,3724},{2838,3999},{2839,3793},{2842,4745},{2845,3888},{2848,3932},{2849,3886},{2852,4550},{2853,3824},{2855,3777},{2858,3955},{2859,3882},{2860,3781},{2861,3776},{2866,3809},{2867,3737},{2871,4390},{2872,4186},{2875,3907},{2876,3767},{2878,4044},{2886,3900},{2889,3880},{2893,4011},{2895,3835},{2897,4782},{2898,3801},{2901,3995},{2904,4336},{2907,3935},{2909,3822},{2912,3916},{2914,3971},{2923,4197},{2924,4109},{2929,3927},{2930,3872},{2933,4192},{2934,4135},{2936,3923},{2940,3841},{2941,3798},{2945,4152},{2948,3948},{2950,3944},{2952,4027},{2959,4138},{2962,4199},{2963,4160},{2964,3921},{2966,4082},{2967,3896},{2968,3795},{2976,4151},{2977,3982},{2978,3966},{2983,3998},{2988,4779},{2989,4231},{2990,4121},{2991,4081},{2995,4074},{2996,3965},{2999,4363},{3000,4060},{3003,4302},{3009,4237},{3010,4017},{3011,3952},{3014,4443},{3017,4010},{3019,4037},{3023,4103},{3028,4176},{3029,4141},{3030,3914},{3034,4107},{3035,4070},{3041,4111},{3043,4051},{3045,4128},{3050,4249},{3051,4016},{3053,4097},{3055,3961},{3059,4700},{3060,4049},{3063,4330},{3066,3877},{3069,4278},{3072,4150},{3074,4057},{3076,3821},{3080,4263},{3081,4033},{3086,4140},{3087,4100},{3091,4447},{3092,4234},{3093,4219},{3094,4120},{3096,4223},{3105,4324},{3108,4449},{3112,4503},{3115,4222},{3123,4119},{3127,4173},{3132,4429},{3133,4184},{3136,4195},{3137,4146},{3140,4262},{3143,4210},{3147,4209},{3150,4026},{3152,4253},{3153,4169},{3158,4243},{3162,4272},{3165,4182},{3167,4563},{3168,4361},{3171,4543},{3174,4683},{3175,4271},{3181,4300},{3184,4395},{3187,4068},{3189,4291},{3192,4296},{3195,4247},{3199,4348},{3204,4307},{3209,4338},{3211,4261},{3212,4172},{3215,4314},{3216,4277},{3220,4343},{3221,4319},{3223,4992},{3224,4506},{3227,4495},{3228,4446},{3231,4425},{3234,4373},{3237,4375},{3239,4305},{3243,4528},{3249,4454},{3256,4471},{3257,4345},{3260,4610},{3264,4581},{3265,4290},{3268,4547},{3271,4549},{3272,4310},{3275,4356},{3277,4539},{3278,4270},{3280,4165},{3283,4526},{3285,4341},{3291,4493},{3293,4473},{3296,4546},{3301,4678},{3306,4453},{3308,4452},{3309,4442},{3310,4384},{3316,4466},{3320,4288},{3322,4511},{3329,4416},{3331,4298},{3337,4317},{3347,4663},{3348,4635},{3349,4523},{3354,4744},{3357,4519},{3361,4383},{3364,4522},{3366,4525},{3370,4650},{3371,4552},{3383,4438},{3387,4399},{3389,4914},{3390,4622},{3398,4532},{3399,4468},{3400,4372},{3402,4559},{3404,4434},{3407,4489},{3411,4579},{3415,4810},{3417,4725},{3421,4631},{3427,4897},{3428,4691},{3429,4605},{3430,4478},{3432,4398},{3435,4690},{3436,4601},{3438,4487},{3440,4712},{3443,4571},{3446,4675},{3447,4670},{3448,4599},{3452,4567},{3453,4437},{3457,4803},{3458,4595},{3462,4945},{3469,4578},{3473,4892},{3474,4856},{3477,4708},{3482,4660},{3483,4628},{3485,4733},{3486,4621},{3490,4882},{3491,4717},{3492,4674},{3494,4809},{3497,4681},{3505,4847},{3514,4836},{3515,4742},{3517,4751},{3521,4657},{3524,4763},{3527,4876},{3528,4761},{3531,4969},{3532,4722},{3540,4789},{3542,4181},{3551,4773},{3555,4850},{3557,4832},{3562,4705},{3567,4941},{3568,4644},{3574,4786},{3576,4921},{3577,4740},{3580,4768},{3582,4979},{3583,4778},{3588,4967},{3591,4928},{3594,4818},{3595,4772},{3596,4586},{3603,4839},{3607,4428},{3609,4801},{3612,4889},{3613,4652},{3616,4939},{3617,4871},{3623,4821},{3625,4765},{3631,4935},{3633,4926},{3634,4807},{3637,4845},{3642,4977},{3645,4814},{3654,4959},{3655,4907},{3661,4972},{3662,4878},{3663,4771},{3669,4865},{3675,4888},{3680,4956},{3686,4775},{3692,4948},{3717,4903},{3726,4932},{3742,5000},{3750,4732},{3753,4953},
};

int main(){
	int T; cin>>T;
	while(T--){
		int a, b; read(a), read(b); if(a>b) swap(a, b);
		if(buf.count({a, b})) puts("Bob");
		else puts("Alice");
	}	
    return 0;
}

B

用初中平面几何导个角就出来了。

#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define debug(x) cerr << #x << ": " << x << endl
#define pb(a) push_back(a)
#define set0(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define dwn(i,a,b) for(int i=(a);i>=(b);i--)
#define ceil(a,b) (a+(b-1))/b
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define ll_INF 0x7f7f7f7f7f7f7f7f
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;

inline void read(int &x) {
    int s=0;x=1;
    char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-')x=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+ch-'0',ch=getchar();
    x*=s;
}

const double eps=1e-9;

int main(){
	double r, a, b, h; cin>>r>>a>>b>>h;
	
	double ang=atan2(2*h, (a-b));
	double ang2=ang/2;
	
	double g=tan(ang2)*r;
	double d=(g-b/2)*tan(ang);
	
	if(b>2*r) puts("Drop");
	else{
		puts("Stuck");
		printf("%.10lf", d+r);
	}
    return 0;
}

D

签到,队友写的。

F

脑筋急转弯(用数位 dp 搞也可),发现 \(100\) 及以上的数字一定是满足的。

#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define debug(x) cerr << #x << ": " << x << endl
#define pb(a) push_back(a)
#define set0(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define dwn(i,a,b) for(int i=(a);i>=(b);i--)
#define ceil(a,b) (a+(b-1))/b
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define ll_INF 0x7f7f7f7f7f7f7f7f
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;

#define int long long

inline void read(int &x) {
    int s=0;x=1;
    char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-')x=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+ch-'0',ch=getchar();
    x*=s;
}

int f[105];
void init(){
	f[0]=0;
	rep(i,1,9) if(i%3==0) f[i]=1;
	rep(i,10,99) if(i%3==0 || (i%10)%3==0 || (i/10)%3==0) f[i]=1;
	f[100]=1;
	rep(i,1,100) f[i]+=f[i-1]; 
}

int cal(int x){
	if(x<100) return f[x];
	return f[100]+x-100;
}

signed main(){
	init();
	int T; cin>>T;
	while(T--){
		int l, r; read(l), read(r);
		cout<<cal(r)-cal(l-1)<<endl;
	}
	
    return 0;
}

H

FFT.
题意等价于要你找出一个最小的数 \(seed\) ,使得对于数列的任意两个数的差都不被 \(seed\) 整除。

我们利用生成函数的思想,构造出函数:

\[f(x)g(x) = \sum_{i=1}^n x^{a_i} \times \sum_{i=1}^n x^{-a_i} \]

借此来刻画任意两个数组合、作差。

但是次数存在负数如何解决呢?
我们可以给负数那边加上一个偏移量 \(p=500000\) ,以保证次数为正,那么得到的函数对应的次数因为偏移量 \(p\) 的原因到最后再减去 \(p\) 就可以了,复杂度为 $$O(PlogP)$$ 。

最后我们枚举一下因子,看看相应的因子是否满足题意,这一步的复杂度也为 \(O(PlogP)\)

#include<bits/stdc++.h>
using namespace std;

const int p=5e5, M=3e6+5;
const double pi=acos(-1);

int n;

struct Complex{
	double x, y;
	Complex operator + (const Complex &o)const { return {x+o.x, y+o.y}; }
	Complex operator - (const Complex &o)const { return {x-o.x, y-o.y}; }
	Complex operator * (const Complex &o)const { return {x*o.x-y*o.y, x*o.y+y*o.x}; }
};

Complex a[M], b[M];
int res[M];

int rev[M], bit, tot;

void fft(Complex a[], int inv){
	for(int i=0; i<tot; i++) if(i<rev[i]) swap(a[i], a[rev[i]]);
	
	for(int mid=1; mid<tot; mid<<=1){
		auto w1=Complex({cos(pi/mid), inv*sin(pi/mid)});
		for(int i=0; i<tot; i+=mid*2){
			auto wk=Complex({1, 0});
			for(int j=0; j<mid; j++, wk=wk*w1){
				auto x=a[i+j], y=wk*a[i+j+mid];
				a[i+j]=x+y, a[i+j+mid]=x-y;
			}
		}
	}
}

int main(){
	cin>>n;
	for(int i=0; i<n; i++){
		int x; scanf("%d", &x);
		a[x]=Complex({1, 0});
		b[p-x]=Complex({1, 0});
	}
	
	while((1<<bit)<2*p+1) bit++;

	tot=1<<bit;
	// cerr<<tot<<endl;
	
	for(int i=0; i<tot; i++) rev[i]=(rev[i>>1]>>1)|((i&1)<<(bit-1));
	
	fft(a, 1), fft(b, 1);
	
	for(int i=0; i<tot; i++) a[i]=a[i]*b[i];
	
	fft(a, -1);

	for(int i=p; i<=2*p; i++){
		int t=a[i].x/tot+0.5; 
		if(t) res[i-p]=1;
	}
	// cerr<<tot<<endl;
	
	for(int i=n; i<=p+1; i++){
		bool ok=true;
		for(int j=i; j<=p+1; j+=i) if(res[j]){
			ok=false;
			break;
		}
		if(ok){
			cout<<i;
			return 0;
		}
	}
	return 0;
}

K

玄学 + 贪心。
枚举每一对数,当交换更优就交换,做几遍精度就够了。

#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define debug(x) cerr << #x << ": " << x << endl
#define pb(a) push_back(a)
#define set0(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define dwn(i,a,b) for(int i=(a);i>=(b);i--)
#define ceil(a,b) (a+(b-1))/b
#define INF 0x3f3f3f3f
#define ll_INF 0x7f7f7f7f7f7f7f7f
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;

inline void read(int &x) {
    int s=0;x=1;
    char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-')x=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+ch-'0',ch=getchar();
    x*=s;
}

const int N=1010;

int w[N];
double s[N];

double f(int x, int y){
	return s[abs(x-y)];
}

int main(){
	rep(i,0,N-1) s[i]=sqrt(i);
	
	int T; cin>>T;
	while(T--){
		int n; read(n);
		rep(i,1,n) read(w[i]);
		
// 		sort(w+1, w+1+n);
		
		rep(k,1,3){
			rep(i,1,n) rep(j,i+1,n) if(f(w[i], i-1)+f(w[j], j-1)>f(w[j], i-1)+f(w[i], j-1)) swap(w[i], w[j]);
		}
		
		rep(i,1,n) cout<<w[i]<<' ';
		cout<<endl;
	}	
    return 0;
}
posted @ 2021-07-23 21:50  HinanawiTenshi  阅读(544)  评论(0编辑  收藏  举报