• NIOP模拟17.10.13


    太水,简述一下题意

    T1

    让你计算一个形如Σai * bi^ki

    快速幂即可

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cmath>
     4 #include <cstdlib>
     5 #include <cstring>
     6 #include <ctime>
     7 #define min(a, b) ((a) < (b) ? (a) : (b))
     8 #define max(a, b) ((a) > (b) ? (a) : (b))
     9 
    10 inline void swap(long long &x, long long &y)
    11 {
    12     long long tmp = x;x = y;y = tmp;
    13 }
    14 
    15 inline void read(long long &x)
    16 {
    17     x = 0;char ch = getchar(), c = ch;
    18     while(ch < '0' || ch > '9')c = ch, ch = getchar();
    19     while(ch <= '9' && ch >= '0')x = x * 10 + ch - '0', ch = getchar();
    20     if(c == '-')x = -x;
    21 }
    22 
    23 const long long INF = 0x3f3f3f3f;
    24 const long long MAXN = 1000000;
    25 
    26 long long n,k,MOD,ans,x;
    27 
    28 long long pow(long long a, long long b)
    29 {
    30     long long r = 1, base = a;
    31     for(;b;b >>= 1)
    32     {
    33         if(b & 1) r *= base, r %= MOD;
    34         base *= base, base %= MOD;
    35     }
    36     return r;
    37 }
    38 
    39 long long tmp[100000], tot, a[MAXN], b[MAXN];
    40 
    41 int main()
    42 {
    43     freopen("digits.in", "r", stdin);
    44     freopen("digits.out", "w", stdout);
    45     read(n), read(k);
    46     MOD = 1;
    47     for(register long long i = 1;i <= k;++ i) MOD *= 10;
    48     for(register long long i = 1;i <= n;++ i)
    49         read(a[i]), read(b[i]);
    50     read(x);
    51     for(register long long i = 1;i <= n;++ i)
    52     {
    53         ans += (pow(x, b[i]) * a[i])%MOD, ans %= MOD;
    54     }
    55     for(register long long i = 1;i <= k;++ i)
    56     {
    57         tmp[++tot] = ans % 10;
    58         ans /= 10;
    59     }
    60     for(register long long i = k;i >= 1;-- i)
    61         printf("%d
    ", tmp[i]);
    62     return 0;
    63 }
    T1

    T2

    让你求a1 * x1 - x2 * x2 + x3 * x3 - a4 * x4 + a5 * x5 - a6 * x6 = 0在(0,k]内的解的个数,ai <= 10^5, k <= 600

    meet in the middle可过,map做

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cmath>
     4 #include <cstdlib>
     5 #include <cstring>
     6 #include <ctime>
     7 #include <map>
     8 #define min(a, b) ((a) < (b) ? (a) : (b))
     9 #define max(a, b) ((a) > (b) ? (a) : (b))
    10 
    11 inline void swap(long long &x, long long &y)
    12 {
    13     long long tmp = x;x = y;y = tmp;
    14 }
    15 
    16 inline void read(long long &x)
    17 {
    18     x = 0;char ch = getchar(), c = ch;
    19     while(ch < '0' || ch > '9')c = ch, ch = getchar();
    20     while(ch <= '9' && ch >= '0')x = x * 10 + ch - '0', ch = getchar();
    21     if(c == '-')x = -x;
    22 }
    23 
    24 const long long INF = 0x3f3f3f3f;
    25 
    26 std::map<long long, long long> mp;
    27 long long num1[4], num2[4], k, ans;
    28 
    29 int main()
    30 {
    31     freopen("equation.in", "r", stdin);
    32     freopen("equation.out", "w", stdout);
    33     read(k);
    34     for(register long long i = 1;i <= 6;++ i)
    35     {
    36         if(i & 1)read(num1[(i - 1)/2 + 1]);
    37         else read(num2[(i - 1)/2 + 1]);
    38     }
    39     for(register long long i = 1;i <= k;++ i)
    40         for(register long long j = 1;j <= k;++ j)
    41             for(register long long q = 1;q <= k;++ q)
    42                 ++ mp[i * num1[1] + j * num1[2] + q * num1[3]]; 
    43     for(register long long i = 1;i <= k;++ i)
    44         for(register long long j = 1;j <= k;++ j)
    45             for(register long long q = 1;q <= k;++ q)
    46                 if(mp.count(i * num2[1] + j * num2[2] + q * num2[3]))
    47                     ans += mp[i * num2[1] + j * num2[2] + q * num2[3]];
    48     printf("%lld
    ", ans);
    49     return 0;
    50 }
    T2

    T3

    让你求图上1到n的路径上的最大权值最小是多少

    最小生成树 + dfs骚操作

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <cstring>
     5 #include <algorithm>
     6 #define min(a, b) ((a) < (b) ? (a) : (b))
     7 #define max(a, b) ((a) > (b) ? (a) : (b))
     8 
     9 inline void swap(long long &x, long long &y)
    10 {
    11     long long tmp = x;x = y;y = tmp;
    12 }
    13 
    14 inline void read(long long &x)
    15 {
    16     x = 0;char ch = getchar(), c = ch;
    17     while(ch < '0' || ch > '9')c = ch, ch = getchar();
    18     while(ch <= '9' && ch >= '0')x = x * 10 + ch - '0', ch = getchar();
    19     if(c == '-')x = -x;
    20 }
    21 
    22 const long long INF = 0x3f3f3f3f;
    23 const long long MAXN = 1000000 + 10;
    24 
    25 long long u[MAXN], v[MAXN], w[MAXN], cnt[MAXN];
    26 
    27 struct Edge
    28 {
    29     long long u,v,w,next;
    30     Edge(long long _u, long long _v, long long _next, long long _w){w = _w;u = _u, v = _v,next = _next;}
    31     Edge(){}
    32 }edge[MAXN << 1];
    33 long long head[MAXN], cntt;
    34 
    35 inline void insert(long long a, long long b, long long c)
    36 {
    37     edge[++cntt] = Edge(a,b,head[a],c);
    38     head[a] = cntt;
    39 }
    40 
    41 long long n,m,k,fa[MAXN];
    42 
    43 long long find(long long x)
    44 {
    45     return fa[x] == x ? x : fa[x] = find(fa[x]);
    46 }
    47 
    48 long long cmp(long long a, long long b)
    49 {
    50     return w[a] < w[b];
    51 }
    52 
    53 long long ans, b[MAXN];
    54 
    55 long long dfs(long long u)
    56 {
    57     b[u] = 1;
    58     for(register long long pos = head[u];pos;pos = edge[pos].next)
    59     {
    60         long long v = edge[pos].v;
    61         if(v == n)
    62         {
    63             ans = max(ans, edge[pos].w);
    64             return 1;
    65         }
    66         if(b[v]) continue;
    67         if(dfs(v))
    68         {
    69             ans = max(ans, edge[pos].w);
    70             return 1;
    71         }
    72     }
    73     return 0;
    74 }
    75 
    76 int main()
    77 {
    78     freopen("graph.in", "r", stdin);
    79     freopen("graph.out", "w", stdout);
    80     read(n), read(m), read(k);
    81     for(register long long i = 1;i <= m;++ i)
    82         read(u[i]), read(v[i]), read(w[i]), cnt[i] = i;
    83     std::sort(cnt + 1, cnt + 1 + m, cmp);
    84     for(register long long i = 1;i <= n;++ i) fa[i] = i;
    85     for(register long long p = 1;p <= m;++ p)
    86     {
    87         long long i = cnt[p];
    88         long long f1 = find(u[i]), f2 = find(v[i]);
    89         if(f1 == f2)continue;
    90         fa[f1] = f2;
    91         insert(u[i], v[i], w[i]);
    92         insert(v[i], u[i], w[i]);
    93     }
    94     dfs(1);
    95     if(ans == 0)ans = -1;
    96     printf("%lld", ans);
    97     return 0;
    98 }
    T3
  • 相关阅读:
    利用freopen()函数和fc命令简化程序调试
    A Guide to the Multiboot Process
    略谈cpu架构种类
    RHEL与Centos
    九度 1470 调整方阵
    九度 1481 Is It A Tree?
    九度 1548 平面上的点(技巧题)
    九度 1547 出入栈(递推DP)
    2014年王道论坛研究生机试练习赛(一) set 1 GrassLand密码
    13年10月 月赛第一场 set 4 迷宫问题
  • 原文地址:https://www.cnblogs.com/huibixiaoxing/p/7662082.html
Copyright © 2020-2023  润新知