当前位置:网站首页>Arc135 a (time complexity analysis)
Arc135 a (time complexity analysis)
2022-07-04 05:35:00 【Find a derivative first】
subject
The question : take x decomposition , Make the product of all numbers after decomposition reach the maximum . about x, It can be broken down into x/2( Round up ) and x/2( Round down )
Ideas : Memory search . When x<=4, Don't divide . otherwise , Keep dividing .
Time complexity : O(logX) or O(logX * loglogX)
use unordered_map
hypothesis n = 2 ^ k,T(n) = T(n/2)+1.T(n) = k = logn
hypothesis n != 2^k, 2^k-1 <= n < 2^k, It can be proved that at most 2k Time f(x),T(n) < 2 * (log(x)+1) = O(log(x)).
If the map
It takes time to memorize logn Time for ,n At most 2(log(x)+1).logn As mentioned above loglogX Time .
Code :
// Problem: A - Floor, Ceil - Decomposition
// Contest: AtCoder - AtCoder Regular Contest 135
// URL: https://atcoder.jp/contests/arc135/tasks/arc135_a
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<complex>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<unordered_map>
#include<list>
#include<set>
#include<queue>
#include<stack>
#define OldTomato ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define fir(i,a,b) for(int i=a;i<=b;++i)
#define mem(a,x) memset(a,x,sizeof(a))
#define p_ priority_queue
// round() rounding ceil() Rounding up floor() Rounding down
// lower_bound(a.begin(),a.end(),tmp,greater<ll>()) First less than or equal to
// #define int long long //QAQ
using namespace std;
typedef complex<double> CP;
typedef pair<int,int> PII;
typedef long long ll;
// typedef __int128 it;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const ll inf = 1e18;
const int N = 2e5+10;
const int M = 1e6+10;
const int mod = 998244353;
const double eps = 1e-6;
inline int lowbit(int x){
return x&(-x);}
template<typename T>void write(T x)
{
if(x<0)
{
putchar('-');
x=-x;
}
if(x>9)
{
write(x/10);
}
putchar(x%10+'0');
}
template<typename T> void read(T &x)
{
x = 0;char ch = getchar();ll f = 1;
while(!isdigit(ch)){
if(ch == '-')f*=-1;ch=getchar();}
while(isdigit(ch)){
x = x*10+ch-48;ch=getchar();}x*=f;
}
#define int long long
int n,m,k,T;
map<int,int> mp;
int fun(int x)
{
if(x<=4)
{
return x;
}
if(mp[x]) return mp[x];
if(x&1) return mp[x] = fun(x/2) * fun((x+1)/2) % mod;
else return mp[x] = fun(x/2) * fun(x/2) % mod;
}
void solve()
{
read(n);
write(fun(n)); puts("");
}
signed main(void)
{
T = 1;
// OldTomato; cin>>T;
// read(T);
while(T--)
{
solve();
}
return 0;
}
边栏推荐
- Analysis of classical pointer and array written test questions in C language
- Basic concept of bus
- Build an Internet of things infrared temperature measuring punch in machine with esp32 / rush to work after the Spring Festival? Baa, no matter how hard you work, you must take your temperature first
- KMP match string
- 1480. Dynamic sum of one-dimensional array
- Flink1.13 basic SQL syntax (II) join operation
- 19. Framebuffer application programming
- [MySQL practice of massive data with high concurrency, high performance and high availability -8] - transaction isolation mechanism of InnoDB
- BUU-Pwn-test_ your_ nc
- Zzulioj:1201: mode problem
猜你喜欢

Enterprise level log analysis system elk (if things backfire, there must be other arrangements)

Character types of C language

1480. 一维数组的动态和

Solar insect killing system based on single chip microcomputer
![[interested reading] advantageous filtering modeling on long term user behavior sequences for click through rate pre](/img/3e/b5df691ca1790469eb1b4e8ea5b4c0.png)
[interested reading] advantageous filtering modeling on long term user behavior sequences for click through rate pre
![[技术发展-25]:广播电视网、互联网、电信网、电网四网融合技术](/img/87/e0469e280365ed0261e2b551ebd888.png)
[技术发展-25]:广播电视网、互联网、电信网、电网四网融合技术

C language simple student management system (including source code)

1480. Dynamic sum of one-dimensional array
![BUU-Crypto-[GXYCTF2019]CheckIn](/img/b8/ad6c05977f6943f30e9975acb6eb6e.jpg)
BUU-Crypto-[GXYCTF2019]CheckIn

2022G2电站锅炉司炉特种作业证考试题库及答案
随机推荐
June 2022 summary
2022G2电站锅炉司炉特种作业证考试题库及答案
C语言简易学生管理系统(含源码)
【兴趣阅读】Adversarial Filtering Modeling on Long-term User Behavior Sequences for Click-Through Rate Pre
How to configure static IP for Kali virtual machine
Zzulioj:1201: mode problem
Appearance of LabVIEW error dialog box
拓扑排序和关键路径的图形化显示
c语言经典指针和数组笔试题解析
Simulink and Arduino serial port communication
Daily question brushing record (12)
补某视频网站的js,进行视频解密
(4) Canal multi instance use
Letter meaning and parameter abbreviation of optical module Daquan
JS string splicing enhancement
VB. Net GIF (making and disassembling - optimizing code, class library - 5)
Programming example of stm32f1 and stm32subeide -74hc595 drives 4-bit 7-segment nixie tube
Flink1.13 SQL basic syntax (I) DDL, DML
1.1 history of Statistics
Character types of C language