2014黑龙江ACM省赛热身题

传送门


背景:   新组合拿14年的省赛来练练手


第一题:yf大佬貌似很早就翻译出来了...

           题目大意:给你n个字符串,输出这些字符串中里最大的贡献值

         每个字符的贡献值如下:

         小写元音:a,e,i,o,u 贡献为5分

         小写非元音:贡献为1分

         大写元音:a,e,i,o,u 贡献为10分

         大写非元音:贡献为2分

题解:遍历每个字符串,得出每个字符串的贡献值,并作一个ans的更新

#include <iostream>
#include <cstdio>
#include <string>

using namespace std;


int main(){

    int n ;
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    while(cin >> n && n){
        int ans = 0;
        while(n--){
           int tp = 0 ;
          string str;
            cin >> str;
            int len = str.length();
            for(int i = 0 ; i < len; i++){
                 bool s = false;
                 if( 'A'<= str[i] && str[i] <='Z' )  { s = true; str[i] = str[i]-'A'+'a' ; }

                 if(str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u'){
                    if(s)  tp +=10;
                    else   tp+= 5;
                 }
                 else{
                     if(s)  tp += 2;
                    else   tp += 1;
                 }
            }
            ans = max(ans,tp);
        }
      cout << ans << endl;
    }

}


题二:巨无语的数论题...

题意:问LCM(a,b,c)%mod的值是多少?



吐槽:

后来我越感觉越不对....LCM(a,b,c) %mod  != LCM(a%mod,b%mod,c%mod)%mod;

连WA13次..

后来想到应该跟因子有关...


其实这是算术基本定理的一个性质.....

LCM(a,b) = p1^max(a1,b1) * p2^max(a2,b2) * .......

吐血中....


然后这题也给了一个启发...(如何记录并更新 素数因子呢?)

记录可以用map<int,int>tp   更新用map<int,int>kg

       for(it = tp.begin() ; it != tp.end() ; it++){ if(kg[it->first] < it->second ) kg[it->first] = it->second;  } //更新新的因子

如何保证因子都是素因子呢?

 for(int k = 2 ; k * k <= d ; k++){
                 while(d % k == 0 && d != 0){
                      tp[k]++;
                      d/=k;
                   }
              }
             if(d != 0)  tp[d]++;

第二个while是精髓的精髓!!!


#include <iostream>
#include <cstring>
#include <map>
#define LL long long
#define mod 1000000007
using namespace std;


LL kus(LL a,LL b ,LL m){

     LL ans = 1;
     while(b){
        if(b&1) { ans *= a;  ans %= mod ;}
        a = (a*a)%mod;
        b >>= 1;
     }
     return ans;
}

int main(){
    int n ;
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    map<LL,LL>::iterator it;
    while(cin >> n ){
        LL d;
        map<LL,LL> kg;
        for(int i = 0 ; i < 3 ; i++){
            map<LL,LL>tp;
          for(int j = 0 ; j < n ;j++){
             cin >> d;
             for(int k = 2 ; k * k <= d ; k++){
                 while(d % k == 0 && d != 0){
                      tp[k]++;
                      d/=k;
                   }
              }
             if(d != 0)  tp[d]++;
          }
          for(it = tp.begin() ; it != tp.end() ; it++){ if(kg[it->first] < it->second ) kg[it->first] = it->second;  } //更新新的因子
        }
          LL ans = 1;

          for(it = kg.begin() ; it != kg.end() ; it++){  ans = (ans * kus(it->first,it->second,mod))%mod;  }

           cout << ans <<endl;
       }

    }


第三题:

这题本不想打表...但是如果可以打表...为啥不打?高效简单....


题意:给一个数n,问那些数的因子之和等于n


一看数据...10000W果断打表

打表细节: mp[i] 代表整数i的因子之和


#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;
const int mmax = 1e4+1;
int mp[mmax] = {0,1,3,4,7,6,12,8,15,13,18,12,28,14,24,24,31,18,39,20,42,32,36,24,60,31,42,40,56,30,72,32,63,48,54,48,91,38,60,56,90,42,96,44,84,78,72,48,124,57,93,72,98,54,120,72,120,80,90,60,168,62,96,104,127,84,144,68,126,96,144,72,195,74,114,124,140,96,168,80,186,121,126,84,224,108,132,120,180,90,234,112,168,128,144,120,252,98,171,156,217,102,216,104,210,192,162,108,280,110,216,152,248,114,240,144,210,182,180,144,360,133,186,168,224,156,312,128,255,176,252,132,336,160,204,240,270,138,288,140,336,192,216,168,403,180,222,228,266,150,372,152,300,234,288,192,392,158,240,216,378,192,363,164,294,288,252,168,480,183,324,260,308,174,360,248,372,240,270,180,546,182,336,248,360,228,384,216,336,320,360,192,508,194,294,336,399,198,468,200,465,272,306,240,504,252,312,312,434,240,576,212,378,288,324,264,600,256,330,296,504,252,456,224,504,403,342,228,560,230,432,384,450,234,546,288,420,320,432,240,744,242,399,364,434,342,504,280,480,336,468,252,728,288,384,432,511,258,528,304,588,390,396,264,720,324,480,360,476,270,720,272,558,448,414,372,672,278,420,416,720,282,576,284,504,480,504,336,819,307,540,392,518,294,684,360,570,480,450,336,868,352,456,408,620,372,702,308,672,416,576,312,840,314,474,624,560,318,648,360,762,432,576,360,847,434,492,440,630,384,864,332,588,494,504,408,992,338,549,456,756,384,780,400,660,576,522,348,840,350,744,560,756,354,720,432,630,576,540,360,1170,381,546,532,784,444,744,368,744,546,684,432,896,374,648,624,720,420,960,380,840,512,576,384,1020,576,582,572,686,390,1008,432,855,528,594,480,1092,398,600,640,961,402,816,448,714,726,720,456,1080,410,756,552,728,480,936,504,882,560,720,420,1344,422,636,624,810,558,864,496,756,672,792,432,1240,434,768,720,770,480,888,440,1080,741,756,444,1064,540,672,600,1016,450,1209,504,798,608,684,672,1200,458,690,720,1008,462,1152,464,930,768,702,468,1274,544,864,632,900,528,960,620,1008,702,720,480,1512,532,726,768,931,588,1092,488,930,656,1026,492,1176,540,840,936,992,576,1008,500,1092,672,756,504,1560,612,864,732,896,510,1296,592,1023,800,774,624,1232,576,912,696,1260,522,1170,524,924,992,792,576,1488,553,972,780,1120,588,1080,648,1020,720,810,684,1680,542,816,728,1134,660,1344,548,966,806,1116,600,1440,640,834,912,980,558,1248,616,1488,864,846,564,1344,684,852,968,1080,570,1440,572,1176,768,1008,744,1651,578,921,776,1260,672,1176,648,1110,1092,882,588,1596,640,1080,792,1178,594,1440,864,1050,800,1008,600,1860,602,1056,884,1064,798,1224,608,1260,960,1116,672,1638,614,924,1008,1440,618,1248,620,1344,960,936,720,1736,781,942,960,1106,684,1872,632,1200,848,954,768,1512,798,1080,936,1530,642,1296,644,1344,1056,1080,648,1815,720,1302,1024,1148,654,1320,792,1302,962,1152,660,2016,662,996,1008,1260,960,1482,720,1176,896,1224,744,2016,674,1014,1240,1281,678,1368,784,1620,912,1152,684,1820,828,1200,920,1364,756,1728,692,1218,1248,1044,840,1800,756,1050,936,1736,702,1680,760,1524,1152,1062,816,1680,710,1296,1040,1350,768,1728,1008,1260,960,1080,720,2418,832,1143,968,1274,930,1596,728,1680,1093,1332,792,1736,734,1104,1368,1512,816,1638,740,1596,1120,1296,744,1920,900,1122,1092,1512,864,1872,752,1488,1008,1260,912,2240,758,1140,1152,1800,762,1536,880,1344,1404,1152,840,2044,770,1728,1032,1358,774,1716,992,1470,1216,1170,840,2352,864,1296,1200,1767,948,1584,788,1386,1056,1440,912,2340,868,1194,1296,1400,798,1920,864,1953,1170,1206,888,1904,1152,1344,1080,1530,810,2178,812,1680,1088,1368,984,2232,880,1230,1456,1764,822,1656,824,1560,1488,1440,828,2184,830,1512,1112,1778,1026,1680,1008,1680,1280,1260,840,2880,871,1266,1128,1484,1098,1872,1064,1674,1136,1674,912,2016,854,1488,1560,1620,858,2016,860,1848,1344,1296,864,2520,1044,1302,1228,1792,960,2160,952,1650,1274,1440,1248,2072,878,1320,1176,2232,882,2223,884,1764,1440,1332,888,2280,1024,1620,1452,1568,960,1800,1080,2040,1344,1350,960,2821,972,1512,1408,1710,1092,1824,908,1596,1326,2016,912,2480,1008,1374,1488,1610,1056,2160,920,2160,1232,1386,1008,2688,1178,1392,1352,1890,930,2304,1140,1638,1248,1404,1296,2730,938,1632,1256,2016,942,1896,1008,1860,1920,1584,948,2240,1036,1860,1272,2160,954,2106,1152,1680,1440,1440,1104,3048,993,1596,1404,1694,1164,2304,968,1995,1440,1764,972,2548,1120,1464,1736,1922,978,1968,1080,2394,1430,1476,984,2520,1188,1620,1536,1960,1056,2808,992,2016,1328,1728,1200,2352,998,1500,1520,2340,1344,2016,1080,1764,1632,1512,1080,3224,1010,1836,1352,2016,1014,2196,1440,1920,1482,1530,1020,3024,1022,1776,1536,2047,1302,2400,1120,1806,1600,1872,1032,2640,1034,1728,1872,2128,1116,2088,1040,2604,1392,1566,1200,2730,1440,1572,1400,1980,1050,2976,1052,1848,1694,1728,1272,3024,1216,1659,1416,2268,1062,2340,1064,2400,1728,1764,1176,2520,1070,1944,1872,2108,1140,2160,1364,1890,1440,2052,1176,3600,1152,1626,1524,1904,1536,2184,1088,2286,1729,1980,1092,3136,1094,1644,1776,2070,1098,2418,1264,2604,1472,1800,1104,2976,1512,1920,1680,1946,1110,2736,1224,2100,1728,1674,1344,2912,1118,1848,1496,3024,1200,2592,1124,1974,2028,1692,1368,2880,1130,2052,1680,1988,1248,2904,1368,2232,1520,1710,1224,3360,1312,1716,1664,2520,1380,2304,1216,2352,1536,2232,1152,3315,1154,1734,2304,2149,1260,2328,1240,2700,1760,2016,1164,2744,1404,1944,1560,2294,1344,3276,1172,2058,1728,1764,1488,3420,1296,1920,1716,2520,1182,2376,1464,2394,1920,1782,1188,3360,1260,2592,1592,2250,1194,2400,1440,2352,2080,1800,1320,3844,1202,1806,1608,2464,1452,2652,1296,2280,1792,2394,1392,2856,1214,1824,2184,2540,1218,2880,1296,2604,1824,2016,1224,3510,1767,1842,1640,2156,1230,3024,1232,2976,1794,1854,1680,2912,1238,1860,1920,2880,1332,2880,1368,2184,2016,2160,1320,3528,1250,2343,1820,2198,1440,2880,1512,2370,1680,2052,1260,4368,1372,1896,1688,2480,1728,2544,1456,2226,1920,2304,1344,3240,1360,2394,2232,2520,1278,2808,1280,3066,1984,1926,1284,3024,1548,1932,2184,2880,1290,3168,1292,2520,1728,1944,1824,3751,1298,2160,1736,3038,1302,3072,1304,2460,2340,1962,1308,3080,1728,2376,1920,2646,1428,2886,1584,2688,1760,1980,1320,4320,1322,1986,2280,2324,1674,3024,1328,2604,1776,2880,1464,3458,1408,2160,2160,2520,1536,2688,1456,2856,1950,2232,1440,4064,1620,2022,1800,2366,1440,3720,1552,2745,2016,2034,1632,3192,1440,2352,1976,3348,1362,2736,1440,2688,2688,2052,1368,3900,1407,2484,1832,2800,1374,2760,1872,2772,2178,2268,1584,4032,1382,2076,1848,2610,1668,3744,1480,2436,1856,2520,1512,3720,1600,2268,2496,2450,1536,2808,1400,3720,1872,2106,1488,3920,1692,2280,2176,3060,1410,3456,1512,2478,2054,2448,1704,3600,1540,2130,2112,3024,1710,3120,1424,2790,2480,2304,1428,4032,1430,3024,2160,2700,1434,2880,2016,2520,1920,2160,1440,4914,1584,2496,2128,2667,1842,2904,1448,2730,2496,2790,1452,3724,1454,2184,2352,3472,1536,3279,1460,3108,1952,2376,1920,3720,1764,2202,2132,2576,1596,4104,1472,3048,1968,2448,1860,3822,1696,2220,2160,3420,1482,3360,1484,3024,2880,2232,1488,3968,1490,2700,2304,2618,1494,3276,2016,3240,2000,2592,1500,4368,1600,2256,2184,3024,2112,3024,1656,2940,2016,2736,1512,4800,1620,2274,2448,2660,1596,3456,1824,3720,2379,2286,1524,3584,1922,2640,2040,2880,1680,4212,1532,2688,2368,2520
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值