Codeforces 1017 CThe Phone Number
題意:給了數n代表數列的長度,要求構造一個數列使得最長上升自序列的長度和最長下降子序列的長度和最小
分析: 構造.我們把這個序列分成若干段,首先滿足最長上升子序列的長度最小的話,就儘可能讓每一段是遞減的,而最長上升子序列的長度和子段有關. 再考慮最長下降子序列,因為已經每一段之間都是遞減的關係,那麼子段遞增才可能儘可能讓遞減序列的長度小. 至於分成多少段,我們假設分成x段,則最長上升子序列的長度為n/x,最長下降子序列的長度為x,我們要使得x+n/x儘可能小就是x=sqrt(n)的時候
程式碼:
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn],tmp[maxn];
vector<int>vec[maxn];
bool cmp(int x,int y)
{
return x > y;
}
int main()
{
int n;
cin>>n;
for(int i = 1; i <= n; i++)
a[i] = i;
int x = (int)sqrt(n);
//printf("%d\n",x);
int r = n % x;
int d = n / x;
if(r != 0)d++;
for(int i = 1; i <= d; i ++)
{
for(int j = (i - 1) * d + 1; j <= i * d && j <= n; j++)
vec[i].push_back(a[j]);
}
for(int i = d; i >= 1; i--)
{
for(int j = 0; j < vec[i].size(); j++)
printf("%d ",vec[i][j]);
}
printf("\n");
return 0;
}
相關文章
- Codeforces466C Number of Ways
- Codeforces 158E Phone Talks:dp
- Leetcode Letter Combinations of a Phone NumberLeetCode
- Leetcode 17 Letter Combinations of a Phone NumberLeetCode
- Leetcode-Letter Combinations of a Phone NumberLeetCode
- Letter Combinations of a Phone Number leetcode javaLeetCodeJava
- Codeforces Round #213 (Div. 2) A. Good NumberGo
- 關於開發者協議Edit Phone Number終極解決方案協議
- cugoj 1017Go
- Leetcode – 017. Letter Combinations of a Phone NumberLeetCode
- CodeForces - 976A:Minimum Binary Number(水題)
- Codeforces Round #228 (Div. 2) A. Fox and Number GameGAM
- Codeforces 245H Queries for Number of Palindromes:區間dp
- LeetCode Letter Combinations of a Phone Number(017)解法總結LeetCode
- 「CF1017G」The Tree
- [LeetCode] Letter Combinations of a Phone Number 電話號碼的字母組合LeetCode
- 1017. 價格查詢
- Codeforces 235E Number Challenge (神定理+莫比烏斯反演)
- 演算法練習--LeetCode--17. Letter Combinations of a Phone Number: 100%演算法LeetCode
- Codeforces Round #231 (Div. 2) B Very Beautiful Number(數字遞推)
- Windows Phone FAQWindows
- Codeforces 27E Number With The Given Amount Of Divisors (求約數個數為n的最小數)
- Codeforces 617E XOR and Favorite Number (區間異或和 莫隊演算法 分塊暴力)演算法
- Windows Phone 體驗Windows
- JavaScript Number()JavaScript
- 一個IT愛好者眼中的Windows Phone和Android PhoneWindowsAndroid
- Oracle System Change Number (SCN) Number 完全筆記Oracle筆記
- HDU-OJ-1017 A Mathematical Curiosity-整數對iOS
- 一起學Windows Phone7開發(十四.一 Phone Task)Windows
- Dribbble for windows phone 8Windows
- 【NUMBER】Oracle的NUMBER資料型別特點Oracle資料型別
- JavaScript Number 物件JavaScript物件
- Number.NaNNaN
- Number of BoomerangsOOM
- Oracle dataguard報錯:Error 1017 received logging on to the standbyOracleError
- Windows Phone 解析圖片格式Windows
- Windows Phone網路HttpWebRequest用法WindowsHTTPWeb
- Windows Phone 7 墓碑機制Windows