瞎搞题gym226123 L. For the Honest Election

Posted suut

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了瞎搞题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;
}

 


以上是关于瞎搞题gym226123 L. For the Honest Election的主要内容,如果未能解决你的问题,请参考以下文章

HDU 4968(杭电多校#9 1009题)Improving the GPA (瞎搞)

The Preliminary Contest for ICPC Asia Shanghai 2019 L. Digit sum

gym-101343I-Husam and the Broken Present 1

[树形DP] The 2021 ICPC Asia Nanjing Regional Contest H题

The 15th Chinese Northeast L. k-th Smallest Common Substring(广义SAM,对节点字典序排序)

Por Costel and the Match Gym - 100923H(经典种类并查集)