zoukankan      html  css  js  c++  java
  • 【瞎搞题】gym226123 L. For the Honest Election

    http://codeforces.com/gym/226123/problem/L

    题解:手摸几组数据,发现一个规律:将n 质因数分解,答案就是 每个质因数/2+1后再乘起来。

      然后考虑2的情况:

    2 8 16 32 64
    1 5 9 15 25
    发现 2,16 要特判  另外8的因子对应乘5
    交上去又发现表格填错了,2 对应的是2 不是1  然后就AC了。 正常做法是dfs

    #define
    _CRT_SECURE_NO_WARNINGS #include<cmath> #include<iostream> #include<stdio.h> #include<algorithm> #include<cstring> using namespace std; #define rep(i,t,n) for(int i =(t);i<=(n);++i) #define per(i,n,t) for(int i =(n);i>=(t);--i) #define mmm(a,b) memset(a,b,sizeof(a)) #define eps 1e-6 const int maxn = 1e6+5; int a[maxn]; int isp[maxn]; int cnt[maxn]; typedef long long ll; struct node { }; ll n; ll ans = n / 2 + 1; void run(int n) { ans = n / 2 + 1; for (ll i = 1; i*i <= n; i++)if (n%i == 0) { ll x = (i / 2 + 1)*(((n / i) / 2) + 1); ans = min(ans, x); } } int main() { rep(i, 1, maxn)isp[i] = 1; rep(i, 2, maxn)if (isp[i]) { for (int j = 2 * i; j <= maxn; j += i)isp[j] = 0; } while (cin >> n) { ll ans = 1; int cnt=0; while (n % 2 == 0)n /= 2, cnt++; while (cnt >= 3) { if (cnt == 4) { cnt -= 4; ans *= 9; } else { cnt -= 3; ans *= 5; } } if (cnt == 1) { ans *= 2; } if (cnt == 2)ans *= 3; rep(i, 3, maxn-1) if(isp[i]){ while (n%i == 0)ans *= (i/2 + 1),n/=i; if (n == 1)break; } ans *= (n/2+1); cout << ans; } } /* qwer qwre 1000000000 */

    dfs:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<vector>
    #include<map>
    #include<queue>
    using namespace std;
    typedef long long ll;
    map<int,int>sp;
    void solve(int t){
        if(sp[t])return ;
        sp[t]=t/2+1;
        for(int i=2;i*i<=t;i++){
            if(t%i==0){
                solve(t/i);
                solve(i);
                sp[t]=min(sp[t],sp[t/i]*(i/2+1));
                sp[t]=min(sp[t],sp[i]*(t/i/2+1));
            }
        }
    }
    int main(){
        int n,i,j;
        scanf("%d",&n);
        solve(n);
        printf("%d
    ",sp[n]);
        return 0;
    }
    成功的路并不拥挤,因为大部分人都在颓(笑)
  • 相关阅读:
    hdu 5119 Happy Matt Friends
    hdu 5128 The E-pang Palace
    hdu 5131 Song Jiang's rank list
    hdu 5135 Little Zu Chongzhi's Triangles
    hdu 5137 How Many Maos Does the Guanxi Worth
    hdu 5122 K.Bro Sorting
    Human Gene Functions
    Palindrome(最长公共子序列)
    A Simple problem
    Alignment ( 最长上升(下降)子序列 )
  • 原文地址:https://www.cnblogs.com/SuuT/p/9356920.html
Copyright © 2011-2022 走看看