• 2014江西理工大学C语言程序竞赛高级组


    Beautiful Palindrome Number

    题意:求N里面有多少个符合要求的数字(数字要求:回文数,且前一半部分是不严格递增)

    解法:打表

    #include<bits/stdc++.h>
    using namespace std;
    int find1(int index)
    {
        int count1 = 0;
        int number = 9;                        //记录数位上的回文数,如个位回文数为9
        int w = 0;                            //记录数位
    
        long half;                            //保存回文数的左半边的结果
        long h = 1;                            //回文数的左半边的起始基数
        long res;                            //结果
    
        while(true)
        {
            if(w > 0 && w%2 == 0)              //每进两个数位,回文数乘以10
            {
                number *= 10;
            }
            w++;                            //数位加一
            if(count1 + number > index)        //回文数大于查找的回数,跳出
                break;
    
            count1+= number;                //回文数加上当前数位上的回文数
        }
    
        index -= count1;                        //在当前数位上的位置。如w=5,index=50,则万位上的第50个回文数是我们所求
    
        for(int i = 0; i < (w-1) / 2; i++)      //求回文数的左半边的基数,如回文数在万位上,则为100
        {
            h *= 10;
        }
    
        half = h + index;                        //回文数的左半边,如100 + 50 = 150
    
        res = half;
    
        if(w%2 != 0)                            //如果为奇数,则中间那个数不必算入右半边了!
            half /=10;
    
        while(half != 0)                          //拼接回文数
        {
            res = res *10 + half % 10;
            half /= 10;
        }
    
        return res;
    }
    int cmd(int x)
    {
        int cot=0;
        int a[1000];
        while(x)
        {
            a[cot++]=x%10;
            x/=10;
        }
        int pos=a[0];
        if(cot%2==0)
        {
            for(int i=1; i<cot/2; i++)
            {
                if(pos<=a[i])
                {
                    pos=a[i];
                }
                else
                {
                    return 0;
                }
            }
        }
        else
        {
            for(int i=1; i<=cot/2; i++)
            {
                if(pos<=a[i])
                {
                    pos=a[i];
                }
                else
                {
                    return 0;
                }
            }
        }
    
        return 1;
    }
    int a[]={1,2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 111, 121, 131, 141, 151, 161, 171, 181, 191, 222, 232, 242, 252, 262, 272, 282, 292, 333, 343, 353, 363, 373, 383, 393, 444, 454, 464, 474, 484, 494, 555, 565, 575, 585, 595, 666, 676, 686, 696, 777, 787, 797, 888, 898, 999, 1111, 1221, 1331, 1441, 1551, 1661, 1771, 1881, 1991, 2222, 2332, 2442, 2552, 2662, 2772, 2882, 2992, 3333, 3443, 3553, 3663, 3773, 3883, 3993, 4444, 4554, 4664, 4774, 4884, 4994, 5555, 5665, 5775, 5885, 5995, 6666, 6776, 6886, 6996, 7777, 7887, 7997, 8888, 8998, 9999, 11111, 11211, 11311, 11411, 11511, 11611, 11711, 11811, 11911, 12221, 12321, 12421, 12521, 12621, 12721, 12821, 12921, 13331, 13431, 13531, 13631, 13731, 13831, 13931, 14441, 14541, 14641, 14741, 14841, 14941, 15551, 15651, 15751, 15851, 15951, 16661, 16761, 16861, 16961, 17771, 17871, 17971, 18881, 18981, 19991, 22222, 22322, 22422, 22522, 22622, 22722, 22822, 22922, 23332, 23432, 23532, 23632, 23732, 23832, 23932, 24442, 24542, 24642, 24742, 24842, 24942, 25552, 25652, 25752, 25852, 25952, 26662, 26762, 26862, 26962, 27772, 27872, 27972, 28882, 28982, 29992, 33333, 33433, 33533, 33633, 33733, 33833, 33933, 34443, 34543, 34643, 34743, 34843, 34943, 35553, 35653, 35753, 35853, 35953, 36663, 36763, 36863, 36963, 37773, 37873, 37973, 38883, 38983, 39993,
    44444, 44544, 44644, 44744, 44844, 44944, 45554, 45654, 45754, 45854, 45954, 46664, 46764, 46864, 46964, 47774, 47874, 47974, 48884, 48984, 49994, 55555, 55655, 55755, 55855, 55955, 56665, 56765, 56865, 56965, 57775, 57875, 57975, 58885, 58985, 59995, 66666, 66766, 66866, 66966, 67776, 67876, 67976, 68886, 68986, 69996, 77777, 77877, 77977, 78887, 78987, 79997, 88888, 88988, 89998, 99999, 111111, 112211, 113311, 114411, 115511, 116611, 117711, 118811, 119911, 122221, 123321, 124421, 125521, 126621, 127721, 128821, 129921, 133331, 134431, 135531, 136631, 137731, 138831, 139931, 144441, 145541, 146641, 147741, 148841, 149941, 155551, 156651, 157751, 158851, 159951, 166661, 167761, 168861, 169961, 177771, 178871, 179971, 188881, 189981, 199991, 222222, 223322, 224422, 225522, 226622, 227722, 228822, 229922, 233332, 234432, 235532, 236632, 237732, 238832, 239932, 244442, 245542, 246642, 247742, 248842, 249942, 255552, 256652, 257752, 258852, 259952, 266662, 267762, 268862, 269962, 277772, 278872, 279972, 288882, 289982, 299992, 333333, 334433, 335533, 336633, 337733, 338833, 339933, 344443, 345543, 346643, 347743, 348843, 349943, 355553, 356653, 357753, 358853, 359953, 366663, 367763, 368863, 369963, 377773, 378873, 379973, 388883, 389983, 399993, 444444, 445544, 446644, 447744, 448844, 449944, 455554, 456654, 457754, 458854, 459954, 466664, 467764, 468864, 469964, 477774, 478874, 479974, 488884, 489984, 499994, 555555, 556655, 557755, 558855, 559955, 566665, 567765, 568865, 569965, 577775, 578875, 579975, 588885, 589985, 599995, 666666, 667766, 668866, 669966, 677776, 678876, 679976, 688886, 689986, 699996, 777777, 778877, 779977, 788887, 789987, 799997, 888888, 889988, 899998, 999999, 1111111, 1112111, 1113111, 1114111, 1115111, 1116111, 1117111, 1118111, 1119111, 1122211, 1123211, 1124211, 1125211, 1126211, 1127211, 1128211, 1129211, 1133311, 1134311, 1135311, 1136311, 1137311, 1138311, 1139311, 1144411, 1145411, 1146411, 1147411, 1148411, 1149411, 1155511, 1156511, 1157511, 1158511, 1159511, 1166611, 1167611, 1168611, 1169611, 1177711, 1178711, 1179711, 1188811, 1189811, 1199911, 1222221, 1223221, 1224221, 1225221, 1226221, 1227221, 1228221, 1229221, 1233321, 1234321, 1235321, 1236321, 1237321, 1238321, 1239321, 1244421, 1245421, 1246421, 1247421, 1248421, 1249421, 1255521, 1256521, 1257521, 1258521, 1259521, 1266621, 1267621, 1268621, 1269621, 1277721, 1278721, 1279721, 1288821, 1289821, 1299921, 1333331, 1334331, 1335331, 1336331, 1337331, 1338331, 1339331, 1344431, 1345431, 1346431, 1347431, 1348431, 1349431, 1355531, 1356531, 1357531, 1358531, 1359531, 1366631, 1367631, 1368631, 1369631, 1377731, 1378731, 1379731, 1388831, 1389831, 1399931, 1444441, 1445441, 1446441, 1447441, 1448441, 1449441, 1455541, 1456541, 1457541, 1458541, 1459541, 1466641, 1467641, 1468641, 1469641, 1477741, 1478741, 1479741, 1488841, 1489841, 1499941, 1555551, 1556551, 1557551, 1558551, 1559551, 1566651, 1567651, 1568651, 1569651, 1577751, 1578751, 1579751, 1588851, 1589851, 1599951, 1666661, 1667661, 1668661, 1669661, 1677761, 1678761, 1679761, 1688861, 1689861, 1699961, 1777771, 1778771, 1779771, 1788871, 1789871, 1799971, 1888881, 1889881, 1899981, 1999991, 2222222, 2223222, 2224222, 2225222, 2226222, 2227222, 2228222, 2229222, 2233322, 2234322, 2235322, 2236322, 2237322, 2238322, 2239322, 2244422, 2245422, 2246422, 2247422, 2248422, 2249422, 2255522, 2256522, 2257522, 2258522, 2259522, 2266622, 2267622, 2268622, 2269622, 2277722, 2278722, 2279722, 2288822, 2289822, 2299922, 2333332, 2334332, 2335332, 2336332, 2337332, 2338332, 2339332, 2344432, 2345432, 2346432, 2347432, 2348432, 2349432, 2355532, 2356532, 2357532, 2358532, 2359532, 2366632, 2367632, 2368632, 2369632, 2377732, 2378732, 2379732, 2388832, 2389832, 2399932, 2444442, 2445442, 2446442, 2447442, 2448442, 2449442, 2455542, 2456542, 2457542, 2458542, 2459542, 2466642, 2467642, 2468642, 2469642, 2477742, 2478742, 2479742, 2488842, 2489842, 2499942, 2555552, 2556552, 2557552, 2558552, 2559552, 2566652, 2567652, 2568652, 2569652, 2577752, 2578752, 2579752, 2588852, 2589852, 2599952, 2666662, 2667662, 2668662, 2669662, 2677762, 2678762, 2679762, 2688862, 2689862, 2699962, 2777772, 2778772, 2779772, 2788872, 2789872, 2799972, 2888882, 2889882, 2899982, 2999992, 3333333, 3334333, 3335333, 3336333, 3337333, 3338333, 3339333, 3344433, 3345433, 3346433, 3347433, 3348433, 3349433, 3355533, 3356533, 3357533, 3358533, 3359533, 3366633, 3367633, 3368633, 3369633, 3377733, 3378733, 3379733, 3388833, 3389833, 3399933, 3444443, 3445443, 3446443, 3447443, 3448443, 3449443, 3455543, 3456543, 3457543, 3458543, 3459543, 3466643, 3467643, 3468643, 3469643, 3477743, 3478743, 3479743, 3488843, 3489843, 3499943, 3555553, 3556553, 3557553, 3558553, 3559553, 3566653, 3567653, 3568653, 3569653, 3577753, 3578753, 3579753, 3588853, 3589853, 3599953, 3666663, 3667663, 3668663, 3669663, 3677763, 3678763, 3679763, 3688863, 3689863, 3699963, 3777773, 3778773, 3779773, 3788873, 3789873, 3799973, 3888883, 3889883, 3899983, 3999993, 4444444, 4445444, 4446444, 4447444, 4448444, 4449444, 4455544, 4456544, 4457544, 4458544, 4459544, 4466644, 4467644, 4468644, 4469644, 4477744, 4478744, 4479744, 4488844, 4489844, 4499944, 4555554, 4556554, 4557554, 4558554, 4559554, 4566654, 4567654, 4568654, 4569654, 4577754, 4578754, 4579754, 4588854, 4589854, 4599954, 4666664, 4667664, 4668664, 4669664, 4677764, 4678764, 4679764, 4688864, 4689864, 4699964, 4777774, 4778774, 4779774, 4788874, 4789874, 4799974, 4888884, 4889884, 4899984, 4999994, 5555555, 5556555, 5557555, 5558555, 5559555, 5566655, 5567655, 5568655, 5569655, 5577755, 5578755, 5579755, 5588855, 5589855, 5599955, 5666665, 5667665, 5668665, 5669665, 5677765, 5678765, 5679765, 5688865, 5689865, 5699965, 5777775, 5778775, 5779775, 5788875, 5789875, 5799975, 5888885, 5889885, 5899985, 5999995, 6666666, 6667666, 6668666, 6669666, 6677766, 6678766, 6679766, 6688866, 6689866, 6699966, 6777776, 6778776, 6779776, 6788876, 6789876, 6799976, 6888886, 6889886, 6899986, 6999996, 7777777, 7778777, 7779777, 7788877, 7789877, 7799977, 7888887, 7889887, 7899987, 7999997, 8888888, 8889888, 8899988, 8999998, 9999999, 11111111, 11122111, 11133111, 11144111, 11155111, 11166111, 11177111, 11188111, 11199111, 11222211, 11233211, 11244211, 11255211, 11266211, 11277211, 11288211, 11299211, 11333311, 11344311, 11355311, 11366311, 11377311, 11388311, 11399311, 11444411, 11455411, 11466411, 11477411, 11488411, 11499411, 11555511, 11566511, 11577511, 11588511, 11599511, 11666611, 11677611, 11688611, 11699611, 11777711, 11788711, 11799711, 11888811, 11899811, 11999911, 12222221, 12233221, 12244221, 12255221, 12266221, 12277221, 12288221, 12299221, 12333321, 12344321, 12355321, 12366321, 12377321, 12388321, 12399321, 12444421, 12455421, 12466421, 12477421, 12488421, 12499421, 12555521, 12566521, 12577521, 12588521, 12599521, 12666621, 12677621, 12688621, 12699621, 12777721, 12788721, 12799721, 12888821, 12899821, 12999921, 13333331, 13344331, 13355331, 13366331, 13377331, 13388331, 13399331, 13444431, 13455431, 13466431, 13477431, 13488431, 13499431, 13555531, 13566531, 13577531, 13588531, 13599531, 13666631, 13677631, 13688631, 13699631, 13777731, 13788731, 13799731, 13888831, 13899831, 13999931, 14444441, 14455441, 14466441, 14477441, 14488441, 14499441, 14555541, 14566541, 14577541, 14588541, 14599541, 14666641, 14677641, 14688641, 14699641, 14777741, 14788741, 14799741, 14888841, 14899841, 14999941, 15555551, 15566551, 15577551, 15588551, 15599551, 15666651, 15677651, 15688651, 15699651, 15777751, 15788751, 15799751, 15888851, 15899851, 15999951, 16666661, 16677661, 16688661, 16699661, 16777761, 16788761, 16799761, 16888861, 16899861, 16999961, 17777771, 17788771, 17799771, 17888871, 17899871, 17999971, 18888881, 18899881, 18999981, 19999991, 22222222, 22233222, 22244222, 22255222, 22266222, 22277222, 22288222, 22299222, 22333322, 22344322, 22355322, 22366322, 22377322, 22388322, 22399322, 22444422, 22455422, 22466422, 22477422, 22488422, 22499422, 22555522, 22566522, 22577522, 22588522, 22599522, 22666622, 22677622, 22688622, 22699622, 22777722, 22788722, 22799722, 22888822, 22899822, 22999922, 23333332, 23344332, 23355332, 23366332, 23377332, 23388332, 23399332, 23444432, 23455432, 23466432, 23477432, 23488432, 23499432, 23555532, 23566532, 23577532, 23588532, 23599532, 23666632, 23677632, 23688632, 23699632, 23777732, 23788732, 23799732, 23888832, 23899832, 23999932, 24444442, 24455442, 24466442, 24477442, 24488442, 24499442, 24555542, 24566542, 24577542, 24588542, 24599542, 24666642, 24677642, 24688642, 24699642, 24777742, 24788742, 24799742, 24888842, 24899842, 24999942, 25555552, 25566552, 25577552, 25588552, 25599552, 25666652, 25677652, 25688652, 25699652, 25777752, 25788752, 25799752, 25888852, 25899852, 25999952, 26666662, 26677662, 26688662, 26699662, 26777762, 26788762, 26799762, 26888862, 26899862, 26999962, 27777772, 27788772, 27799772, 27888872, 27899872, 27999972, 28888882, 28899882, 28999982, 29999992, 33333333, 33344333, 33355333, 33366333, 33377333, 33388333, 33399333, 33444433, 33455433, 33466433, 33477433, 33488433, 33499433, 33555533, 33566533, 33577533, 33588533, 33599533, 33666633, 33677633, 33688633, 33699633, 33777733, 33788733, 33799733, 33888833, 33899833, 33999933, 34444443, 34455443, 34466443, 34477443, 34488443, 34499443, 34555543, 34566543, 34577543, 34588543, 34599543, 34666643, 34677643, 34688643, 34699643, 34777743, 34788743, 34799743, 34888843, 34899843, 34999943, 35555553, 35566553, 35577553, 35588553, 35599553, 35666653, 35677653, 35688653, 35699653, 35777753, 35788753, 35799753, 35888853, 35899853, 35999953, 36666663, 36677663, 36688663, 36699663, 36777763, 36788763, 36799763, 36888863, 36899863, 36999963, 37777773, 37788773, 37799773, 37888873, 37899873, 37999973, 38888883, 38899883, 38999983, 39999993, 44444444, 44455444, 44466444, 44477444, 44488444, 44499444, 44555544, 44566544, 44577544, 44588544, 44599544, 44666644, 44677644, 44688644, 44699644, 44777744, 44788744, 44799744, 44888844, 44899844, 44999944, 45555554, 45566554, 45577554, 45588554, 45599554, 45666654, 45677654, 45688654, 45699654, 45777754, 45788754, 45799754, 45888854, 45899854, 45999954, 46666664, 46677664, 46688664, 46699664, 46777764, 46788764, 46799764, 46888864, 46899864, 46999964, 47777774, 47788774, 47799774, 47888874, 47899874, 47999974, 48888884, 48899884, 48999984, 49999994, 55555555, 55566555, 55577555, 55588555, 55599555, 55666655, 55677655, 55688655, 55699655, 55777755, 55788755, 55799755, 55888855, 55899855, 55999955, 56666665, 56677665, 56688665, 56699665, 56777765, 56788765, 56799765, 56888865, 56899865, 56999965, 57777775, 57788775, 57799775, 57888875, 57899875, 57999975, 58888885, 58899885, 58999985, 59999995, 66666666, 66677666, 66688666, 66699666, 66777766, 66788766, 66799766, 66888866, 66899866, 66999966, 67777776, 67788776, 67799776, 67888876, 67899876, 67999976, 68888886, 68899886, 68999986, 69999996, 77777777, 77788777, 77799777, 77888877, 77899877, 77999977, 78888887, 78899887, 78999987, 79999997, 88888888, 88899888, 88999988, 89999998, 99999999,
    111111111,0};
    int main()
    {
        int t;
        int n;
        cin>>t;
        while(t--)
        {
            cin>>n;
            for(int i=0;;i++)
            {
                if(a[i]==0) break;
                else if(a[i]>n)
                {
                    cout<<i<<endl;
                    break;
                }
            }
        }
        return 0;
    }

    五子棋

    解法:其实不难,判断却非常复杂,首先当然只要判断是否成为5子。然后判断黑白棋的个数是否满足要求,接下来判断是白子后下还是黑子后下。再根据这两种情况判断,具体看代码判断

    #include<bits/stdc++.h>
    #define ll long long
    using namespace std;
    int ans[1000][1000];
    //int n,m,a,b;
    int Min=(1e9);
    string a[20];
    int x1,x2,x3,x4,x5,x6,x7,x8;
    int cmd(char s)
    {
        int M=-1;
        for(int i=0; i<15; i++)
        {
    
            for(int j=0; j<15; j++)
            {
                x1=0,x2=0,x3=0,x4=0,x5=0,x6=0,x7=0,x8=0;
                if(a[i][j]==s)
                {
                    //cot1++;
                    //  cout<<"/"<<endl;
                    int ans1=i;
                    int ans2=j;
                    while(ans1>=0)
                    {
                        if(a[ans1][j]==s)
                        {
                            // a[i][ans2]='.';
                            ans1--;
                            x1++;
                        }
                        else
                        {
                            break;
                        }
                    }
                    //   cout<<x1<<"A"<<endl;
                    ans1=i;
                    ans2=j;
                    //cout<<ans1<<" "<<ans2<<endl;
                    while(ans1<15)
                    {
                        if(a[ans1][j]==s)
                        {
                            // a[ans1][j]='.';
                            ans1++;
                            x2++;
                        }
                        else
                        {
                            break;
                        }
                    }
                    //   cout<<x2<<"B"<<endl;
                    ans1=i;
                    ans2=j;
                    while(ans2>=0)
                    {
                        if(a[i][ans2]==s)
                        {
                            // a[i][ans2]='.';
                            ans2--;
                            x3++;
                        }
                        else
                        {
                            break;
                        }
                    }
                    // cout<<x3<<"C"<<endl;
                    ans1=i;
                    ans2=j;
                    while(ans2<15)
                    {
                        // cout<<i<<" "<<ans2<<endl;
                        // cout<<a[i][ans2]<<endl;
                        if(a[i][ans2]==s)
                        {
                            // cout<<"A"<<endl;
                            // a[i][ans2]='.';
                            ans2++;
                            x4++;
                        }
                        else
                        {
                            break;
                        }
                    }
                    //cout<<x4<<"D"<<endl;
                    ans1=i;
                    ans2=j;
                    while(ans1>=0&&ans2>=0)
                    {
                        if(a[ans1][ans2]==s)
                        {
                            // a[ans1][ans2]='.';
                            ans1--;
                            ans2--;
                            x5++;
                        }
                        else
                        {
                            break;
                        }
                    }
                    //cout<<x5<<endl;
                    ans1=i;
                    ans2=j;
                    while(ans1<15&&ans2<15)
                    {
                        if(a[ans1][ans2]==s)
                        {
                            // a[ans1][ans2]='.';
                            ans1++;
                            ans2++;
                            x6++;
                        }
                        else
                        {
                            break;
                        }
                    }
                    //cout<<x6<<endl;
                    ans1=i;
                    ans2=j;
                    while(ans1>=0&&ans2<15)
                    {
                        if(a[ans1][ans2]==s)
                        {
                            // a[ans1][ans2]='.';
                            ans1--;
                            ans2++;
                            x7++;
                        }
                        else
                        {
                            break;
                        }
                    }
                    // cout<<x7<<endl;
                    ans1=i;
                    ans2=j;
                    while(ans1<15&&ans2>=0)
                    {
                        if(a[ans1][ans2]==s)
                        {
                            //a[ans1][ans2]='.';
                            ans1++;
                            ans2--;
                            x8++;
                        }
                        else
                        {
                            break;
                        }
                    }
                    //  cout<<x1<<" "<<x2<<endl;
                    //  cout<<x3<<" "<<x4<<endl;
                    // cout<<x5<<" "<<x6<<endl;
                    //  cout<<x7<<" "<<x8<<endl;
                    //cout<<x8<<endl;
                    M=max({x1+x2-1,x3+x4-1,x5+x6-1,x7+x8-1,M});
                }
    
            }
            //  M=-1;
        }
        if(M>=5)
        {
            return 1;
        }
        else
        {
            return 0;
        }
    }
    int cmp(char s)
    {
        for(int i=0; i<15; i++)
        {
            for(int j=0; j<15; j++)
            {
                if(a[i][j]==s)
                {
                    a[i][j]='.';
                    for(int k=0; k<15; k++)
                    {
                        //cout<<a[k]<<endl;
                    }
                    // cout<<cmd(s)<<endl;
                    if(!cmd(s))
                    {
                        return 1;
                    }
                    // cout<<endl;
                    a[i][j]=s;
                }
            }
        }
        return 0;
    }
    int main()
    {
    
        int t;
        cin>>t;
        while(t--)
        {
            x1=0,x2=0,x3=0,x4=0,x5=0,x6=0,x7=0,x8=0;
            int M=-1;
            int cot1=0;
            int cot2=0;
            int N=-1;
            for(int i=0; i<15; i++)
            {
                cin>>a[i];
                for(int j=0; j<15; j++)
                {
                    if(a[i][j]=='@')
                    {
                        cot1++;
                    }
                    else if(a[i][j]=='X')
                    {
                        cot2++;
                    }
                }
            }
            if(cot2==cot1+1 || cot1 == cot2)
            {
                int wb = cmd('X');
                int ww = cmd('@');
                if(cot2==cot1+1 && wb)
                {
                    if(ww)
                        cout << "wrong state" << endl;
                    else
                    {
                        if(cmp('X'))cout << "black" << endl;
                        else cout << "wrong state" << endl;
                    }
                }
                else if(ww && cot1 == cot2)
                {
                    if(wb)
                        cout << "wrong state" << endl;
                    else
                    {
                        if(cmp('@'))cout << "white" << endl;
                        else cout << "wrong state" << endl;
                    }
                }
                else if(!wb && !ww)cout << "continue" << endl;
                else cout << "wrong state" << endl;
            }
            else cout << "wrong state" << endl;
        }
        return 0;
    }

    丁丁历险记

    解法:数据不大,跑最短路,再求1-A到A+B哪一个更短

    #include<bits/stdc++.h>
    #define ll long long
    using namespace std;
    int ans[1000][1000];
    int n,m,a,b;
    int Min=(1e9);
    int main()
    {
        int t;
        cin>>t;
        while(t--)
        {
            for(int i=1; i<=200; i++)
            {
                for(int j=1; j<=200; j++)
                {
                    ans[i][j]=Min;
                }
            }
            cin>>a>>b>>m;
            for(int i=1;i<=m;i++)
            {
                int s,e;
                cin>>s>>e;
                if(s!=e)
                {
                ans[s][e]=1;
                ans[e][s]=1;
                }
                ans[s][s]=0;
                ans[e][e]=0;
            }
            for(int k=1; k<=a+b; k++)
            {
                for(int i=1; i<=a+b; i++)
                {
                    for(int j=1; j<=a+b; j++)
                    {
                        ans[i][j]=min(ans[i][j],ans[i][k]+ans[k][j]);
                    }
                }
            }
            int M=(1e9);
            for(int i=1;i<=a;i++)
            {
               M=min(ans[i][a+b],M);
            }
            if(M==(1e9))
            {
                puts("No");
            }
            else
            cout<<M<<endl;
        }
        return 0;
    }

    平行四边形

    解法:数学,重点是知道a,b,c,d是干什么的

    #include<bits/stdc++.h>
    #define ll long long
    using namespace std;
    int main()
    {
        int n;
        int t;
        cin>>t;
        while(t--)
        {
            int a,b,c,d;
            int sum=0;
            cin>>a>>b>>c>>d;
            for(int i=1;i<d;i++)
            {
                if(i*c%d==0)
                {
                    sum+=b-1;
                }
                else
                {
                    sum+=b;
                }
            }
            cout<<sum<<endl;
        }
        return 0;
    }

    木木换班

    解法:结构体排序

    #include<bits/stdc++.h>
    #define ll long long
    using namespace std;
    struct P
    {
        int a,b;
    }He[110000];
    bool cmd(P x,P y)
    {
        if(x.b==y.b)
        {
            return x.a<y.a;
        }
        return x.b>y.b;
    }
    int main()
    {
        int t;
        int n;
        cin>>t;
        while(t--)
        {
            cin>>n;
            for(int i=1;i<=n;i++)
            {
                cin>>He[i].a>>He[i].b;
            }
            sort(He+1,He+n+1,cmd);
            for(int i=1;i<=n;i++)
            {
              //  cout<<He[i].a<<" "<<He[i].b<<endl;
            }
            cout<<He[1].a+He[1].b<<endl;
        }
        return 0;
    }

    0.333333333......

    解法:a*100000....%b然后xjb求

    #include<bits/stdc++.h>
    #define ll long long
    using namespace std;
    int main()
    {
        int t;
        cin>>t;
        while(t--)
        {
            double a,b;
            cin>>a>>b;
            double s=a/b*1.0;
            s*=10000000000000;
           // cout<<s<<endl;
            ll s1=(ll)s;
          //  cout<<s1<<endl;
            if(abs(s1-s)<=1e-8)
            {
                printf("Yes
    ");
            }
            else
            {
                printf("No
    ");
            }
           // printf("[%d,%d]
    ",a-1,b-1);
        }
        return 0;
    }

    定义域

    解法:没啥好说的

    #include<bits/stdc++.h>
    #define ll long long
    using namespace std;
    int main()
    {
        int t;
        cin>>t;
        while(t--)
        {
            int a,b;
            cin>>a>>b;
            printf("[%d,%d]
    ",a-1,b-1);
        }
        return 0;
    }
  • 相关阅读:
    重写、隐藏基类方法(new, override)
    Java FileHandler
    JMS example
    DB Locker
    计算与所有线段都重合的线段数目
    [转载] linux内存 问题
    oracle rownum & rowid mark a good tool
    java Wget Download
    java new way to implement singleton, use enum
    HttpPut Multipart and handle https request.
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/6101183.html
Copyright © 2020-2023  润新知