dlut1223题解-打表

哎,今天的比赛太坑爹了,说多了都是泪水,好吧,这是我打表的第一题,先freopen("out.txt","w",stdout),再粘贴一下就ok;

打表函数

void chat( ){
    for(int x=0;x<=10000;x++){
        for(int i=0;i<=101&&!cha[x];i++){
            for(int j=0;j<=101&&!cha[x];j++){
                for(int k=0;k<101&&!cha[x];k++){
                    if(x==i*i+j*j+k*k){
                        cha[x]=true;
                    }
                }
            }
        }
    }
    int k=0;
    for(int i=0;i<=10000;i++){
        if(!cha[i]){
            printf("%d,",i);
        }
    }
    printf("10001");
 }

ac代码:

#include
#include
#include
using namespace std;
const int maxn=2000;
int ans[maxn]={7,15,23,28,31,39,47,55,60,63,71,79,87,92,95,103,111,112,119,124,127,135,143,151,156,
159,167,175,183,188,191,199,207,215,220,223,231,239,240,247,252,255,263,271,279,284,287,295,303,311,
316,319,327,335,343,348,351,359,367,368,375,380,383,391,399,407,412,415,423,431,439,444,447,448,455,
463,471,476,479,487,495,496,503,508,511,519,527,535,540,543,551,559,567,572,575,583,591,599,604,607,
615,623,624,631,636,639,647,655,663,668,671,679,687,695,700,703,711,719,727,732,735,743,751,752,759,
764,767,775,783,791,796,799,807,815,823,828,831,839,847,855,860,863,871,879,880,887,892,895,903,911,
919,924,927,935,943,951,956,959,960,967,975,983,988,991,999,1007,1008,1015,1020,1023,1031,1039,1047,
1052,1055,1063,1071,1079,1084,1087,1095,1103,1111,1116,1119,1127,1135,1136,1143,1148,1151,1159,1167,
1175,1180,1183,1191,1199,1207,1212,1215,1223,1231,1239,1244,1247,1255,1263,1264,1271,1276,1279,1287,
1295,1303,1308,1311,1319,1327,1335,1340,1343,1351,1359,1367,1372,1375,1383,1391,1392,1399,1404,1407,
1415,1423,1431,1436,1439,1447,1455,1463,1468,1471,1472,1479,1487,1495,1500,1503,1511,1519,1520,1527,
1532,1535,1543,1551,1559,1564,1567,1575,1583,1591,1596,1599,1607,1615,1623,1628,1631,1639,1647,1648,
1655,1660,1663,1671,1679,1687,1692,1695,1703,1711,1719,1724,1727,1735,1743,1751,1756,1759,1767,1775,
1776,1783,1788,1791,1792,1799,1807,1815,1820,1823,1831,1839,1847,1852,1855,1863,1871,1879,1884,1887,
1895,1903,1904,1911,1916,1919,1927,1935,1943,1948,1951,1959,1967,1975,1980,1983,1984,1991,1999,2007,
2012,2015,2023,2031,2032,2039,2044,2047,2055,2063,2071,2076,2079,2087,2095,2103,2108,2111,2119,2127,
2135,2140,2143,2151,2159,2160,2167,2172,2175,2183,2191,2199,2204,2207,2215,2223,2231,2236,2239,2247,
2255,2263,2268,2271,2279,2287,2288,2295,2300,2303,2311,2319,2327,2332,2335,2343,2351,2359,2364,2367,
2375,2383,2391,2396,2399,2407,2415,2416,2423,2428,2431,2439,2447,2455,2460,2463,2471,2479,2487,2492,
2495,2496,2503,2511,2519,2524,2527,2535,2543,2544,2551,2556,2559,2567,2575,2583,2588,2591,2599,2607,
2615,2620,2623,2631,2639,2647,2652,2655,2663,2671,2672,2679,2684,2687,2695,2703,2711,2716,2719,2727,
2735,2743,2748,2751,2759,2767,2775,2780,2783,2791,2799,2800,2807,2812,2815,2823,2831,2839,2844,2847,
2855,2863,2871,2876,2879,2887,2895,2903,2908,2911,2919,2927,2928,2935,2940,2943,2951,2959,2967,2972,
2975,2983,2991,2999,3004,3007,3008,3015,3023,3031,3036,3039,3047,3055,3056,3063,3068,3071,3079,3087,
3095,3100,3103,3111,3119,3127,3132,3135,3143,3151,3159,3164,3167,3175,3183,3184,3191,3196,3199,3207,
3215,3223,3228,3231,3239,3247,3255,3260,3263,3271,3279,3287,3292,3295,3303,3311,3312,3319,3324,3327,
3335,3343,3351,3356,3359,3367,3375,3383,3388,3391,3399,3407,3415,3420,3423,3431,3439,3440,3447,3452,
3455,3463,3471,3479,3484,3487,3495,3503,3511,3516,3519,3520,3527,3535,3543,3548,3551,3559,3567,3568,
3575,3580,3583,3591,3599,3607,3612,3615,3623,3631,3639,3644,3647,3655,3663,3671,3676,3679,3687,3695,
3696,3703,3708,3711,3719,3727,3735,3740,3743,3751,3759,3767,3772,3775,3783,3791,3799,3804,3807,3815,
3823,3824,3831,3836,3839,3840,3847,3855,3863,3868,3871,3879,3887,3895,3900,3903,3911,3919,3927,3932,
3935,3943,3951,3952,3959,3964,3967,3975,3983,3991,3996,3999,4007,4015,4023,4028,4031,4032,4039,4047,
4055,4060,4063,4071,4079,4080,4087,4092,4095,4103,4111,4119,4124,4127,4135,4143,4151,4156,4159,4167,
4175,4183,4188,4191,4199,4207,4208,4215,4220,4223,4231,4239,4247,4252,4255,4263,4271,4279,4284,4287,
4295,4303,4311,4316,4319,4327,4335,4336,4343,4348,4351,4359,4367,4375,4380,4383,4391,4399,4407,4412,
4415,4423,4431,4439,4444,4447,4455,4463,4464,4471,4476,4479,4487,4495,4503,4508,4511,4519,4527,4535,
4540,4543,4544,4551,4559,4567,4572,4575,4583,4591,4592,4599,4604,4607,4615,4623,4631,4636,4639,4647,
4655,4663,4668,4671,4679,4687,4695,4700,4703,4711,4719,4720,4727,4732,4735,4743,4751,4759,4764,4767,
4775,4783,4791,4796,4799,4807,4815,4823,4828,4831,4839,4847,4848,4855,4860,4863,4871,4879,4887,4892,
4895,4903,4911,4919,4924,4927,4935,4943,4951,4956,4959,4967,4975,4976,4983,4988,4991,4999,5007,5015,
5020,5023,5031,5039,5047,5052,5055,5056,5063,5071,5079,5084,5087,5095,5103,5104,5111,5116,5119,5127,
5135,5143,5148,5151,5159,5167,5175,5180,5183,5191,5199,5207,5212,5215,5223,5231,5232,5239,5244,5247,
5255,5263,5271,5276,5279,5287,5295,5303,5308,5311,5319,5327,5335,5340,5343,5351,5359,5360,5367,5372,
5375,5383,5391,5399,5404,5407,5415,5423,5431,5436,5439,5447,5455,5463,5468,5471,5479,5487,5488,5495,
5500,5503,5511,5519,5527,5532,5535,5543,5551,5559,5564,5567,5568,5575,5583,5591,5596,5599,5607,5615,
5616,5623,5628,5631,5639,5647,5655,5660,5663,5671,5679,5687,5692,5695,5703,5711,5719,5724,5727,5735,
5743,5744,5751,5756,5759,5767,5775,5783,5788,5791,5799,5807,5815,5820,5823,5831,5839,5847,5852,5855,
5863,5871,5872,5879,5884,5887,5888,5895,5903,5911,5916,5919,5927,5935,5943,5948,5951,5959,5967,5975,
5980,5983,5991,5999,6000,6007,6012,6015,6023,6031,6039,6044,6047,6055,6063,6071,6076,6079,6080,6087,
6095,6103,6108,6111,6119,6127,6128,6135,6140,6143,6151,6159,6167,6172,6175,6183,6191,6199,6204,6207,
6215,6223,6231,6236,6239,6247,6255,6256,6263,6268,6271,6279,6287,6295,6300,6303,6311,6319,6327,6332,
6335,6343,6351,6359,6364,6367,6375,6383,6384,6391,6396,6399,6407,6415,6423,6428,6431,6439,6447,6455,
6460,6463,6471,6479,6487,6492,6495,6503,6511,6512,6519,6524,6527,6535,6543,6551,6556,6559,6567,6575,
6583,6588,6591,6592,6599,6607,6615,6620,6623,6631,6639,6640,6647,6652,6655,6663,6671,6679,6684,6687,
6695,6703,6711,6716,6719,6727,6735,6743,6748,6751,6759,6767,6768,6775,6780,6783,6791,6799,6807,6812,
6815,6823,6831,6839,6844,6847,6855,6863,6871,6876,6879,6887,6895,6896,6903,6908,6911,6919,6927,6935,
6940,6943,6951,6959,6967,6972,6975,6983,6991,6999,7004,7007,7015,7023,7024,7031,7036,7039,7047,7055,
7063,7068,7071,7079,7087,7095,7100,7103,7104,7111,7119,7127,7132,7135,7143,7151,7152,7159,7164,7167,
7168,7175,7183,7191,7196,7199,7207,7215,7223,7228,7231,7239,7247,7255,7260,7263,7271,7279,7280,7287,
7292,7295,7303,7311,7319,7324,7327,7335,7343,7351,7356,7359,7367,7375,7383,7388,7391,7399,7407,7408,
7415,7420,7423,7431,7439,7447,7452,7455,7463,7471,7479,7484,7487,7495,7503,7511,7516,7519,7527,7535,
7536,7543,7548,7551,7559,7567,7575,7580,7583,7591,7599,7607,7612,7615,7616,7623,7631,7639,7644,7647,
7655,7663,7664,7671,7676,7679,7687,7695,7703,7708,7711,7719,7727,7735,7740,7743,7751,7759,7767,7772,
7775,7783,7791,7792,7799,7804,7807,7815,7823,7831,7836,7839,7847,7855,7863,7868,7871,7879,7887,7895,
7900,7903,7911,7919,7920,7927,7932,7935,7936,7943,7951,7959,7964,7967,7975,7983,7991,7996,7999,8007,
8015,8023,8028,8031,8039,8047,8048,8055,8060,8063,8071,8079,8087,8092,8095,8103,8111,8119,8124,8127,
8128,8135,8143,8151,8156,8159,8167,8175,8176,8183,8188,8191,8199,8207,8215,8220,8223,8231,8239,8247,
8252,8255,8263,8271,8279,8284,8287,8295,8303,8304,8311,8316,8319,8327,8335,8343,8348,8351,8359,8367,
8375,8380,8383,8391,8399,8407,8412,8415,8423,8431,8432,8439,8444,8447,8455,8463,8471,8476,8479,8487,
8495,8503,8508,8511,8519,8527,8535,8540,8543,8551,8559,8560,8567,8572,8575,8583,8591,8599,8604,8607,
8615,8623,8631,8636,8639,8640,8647,8655,8663,8668,8671,8679,8687,8688,8695,8700,8703,8711,8719,8727,
8732,8735,8743,8751,8759,8764,8767,8775,8783,8791,8796,8799,8807,8815,8816,8823,8828,8831,8839,8847,
8855,8860,8863,8871,8879,8887,8892,8895,8903,8911,8919,8924,8927,8935,8943,8944,8951,8956,8959,8967,
8975,8983,8988,8991,8999,9007,9015,9020,9023,9031,9039,9047,9052,9055,9063,9071,9072,9079,9084,9087,
9095,9103,9111,9116,9119,9127,9135,9143,9148,9151,9152,9159,9167,9175,9180,9183,9191,9199,9200,9207,
9212,9215,9223,9231,9239,9244,9247,9255,9263,9271,9276,9279,9287,9295,9303,9308,9311,9319,9327,9328,
9335,9340,9343,9351,9359,9367,9372,9375,9383,9391,9399,9404,9407,9415,9423,9431,9436,9439,9447,9455,
9456,9463,9468,9471,9479,9487,9495,9500,9503,9511,9519,9527,9532,9535,9543,9551,9559,9564,9567,9575,
9583,9584,9591,9596,9599,9607,9615,9623,9628,9631,9639,9647,9655,9660,9663,9664,9671,9679,9687,9692,
9695,9703,9711,9712,9719,9724,9727,9735,9743,9751,9756,9759,9767,9775,9783,9788,9791,9799,9807,9815,
9820,9823,9831,9839,9840,9847,9852,9855,9863,9871,9879,9884,9887,9895,9903,9911,9916,9919,9927,9935,
9943,9948,9951,9959,9967,9968,9975,9980,9983,9984,9991,9999,10001};

int main()
{

    int T;
    scanf("%d",&T);
    while(T--){
        int N;
        scanf("%d",&N);
        int k;
        for(k=0;;k++){
            if(ans[k]>N)break;
        }
        printf("%d\n",k);
    }
    return 0;
}




你可能感兴趣的:(acm-打表,基础,打表,基础)