Codeforces Round #431 (Div. 2) 848A From Y to Y(思维)
来源:互联网 发布:python中执行shell脚本 编辑:程序博客网 时间:2024/06/18 04:58
今早补题感觉思路不错,这题昨天连看都没看,真是菜到无法想象了.
一开始看到,有点懵逼,觉得很难,因为有一些,exactly,minimal,这样的词语,搞得好像这题状况很多一样.
但是仔细看会发现,每一种字符串的形式,他的”操作值”,是固定的,那么,这题就不那么难了.
又分析发现,假如是aaaa这种,他们要合在一起,操作值一定是1+2+3=6,
aaaaa呢,一定是6+4 = 10,也就是一个阶和的情况.
那么这题就容易了,目的变为要把一个n,分解成多个阶和.
使用二分瞎逼写一写就过了.
/* xzppp */#include <iostream>#include <vector>#include <cstdio>#include <string.h>#include <algorithm>#include <queue>#include <map>#include <string>#include <cmath>#include <stack>#include <iomanip>using namespace std;#define FFF freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define MP make_pair#define PB push_backtypedef long long LL;typedef unsigned long long ULL;typedef pair<int,int > pii;typedef pair<double,double > pdd;typedef pair<double,int > pdi;const int MAXN = 1500+17;const int MAXM = 20;const int MAXV = 2*1e3+17;const int INF = 0x7fffffff;const int MOD = 1e9+7;int sum[MAXN];int main(){ #ifndef ONLINE_JUDGE FFF #endif sum[2] = 1; for (int i = 3; i < MAXN; ++i) { sum[i] = sum[i-1] + i-1; } int n; cin>>n; bool can = false; vector<int > ans; int tie = 0; if(n==0) { cout<<"a"<<endl; return 0; } while(!can) { if(tie++>100) break; int pos = (lower_bound(sum, sum+MAXN, n))-sum-1; int x = n; ans.PB(pos); int temp = pos; x -= sum[temp]; while(x>0) { int temp = (lower_bound(sum, sum+MAXN, x))-sum; if(sum[temp]>x) temp--; x -= sum[temp]; ans.push_back(temp); } if(x==0) { can = true; break; } else { ans.clear(); } } for (int i = 0; i < ans.size(); ++i) { for (int j = 0; j < ans[i]; ++j) { printf("%c",i+'a'); } } return 0;}
阅读全文
0 0
- Codeforces Round #431 (Div. 2) 848A From Y to Y(思维)
- Codeforces Round #431 (Div. 2) From Y to Y
- codeforces 848A From Y to Y(思维)
- Codeforces Round #431 (Div. 2) A、Odds and Ends B、Tell Your World C、From Y to Y
- Codeforces Round #431 (Div. 2) C. From Y to Y(补题)
- CodeForces #431 Div. 2 849C From Y to Y 贪心 技巧题
- codeforce 848A From Y to Y
- Codeforces 849C From Y to Y【思维】
- Codeforces From Y to Y
- Codeforces 849 C From Y to Y
- CF 848 A. From Y to Y【模拟】
- Codeforces 849 C. From Y to Y (技巧)
- Codeforces 849 C. From Y to Y 结论题
- Codeforces848A-From Y to Y
- C. From Y to Y
- Codeforces849C From Y to Y
- Codeforces Round #418 (Div. 2)-A. An abandoned sentiment from past-思维
- 【Codeforces Round 330 (Div 2)B】【数值统计 端点思维】Pasha and Phone 电话号码 每块数是x倍数却不能以y开头方案数
- 数学建模--图与网络(1)
- linux tar 打包和 gzip压缩
- ionicframework开发框架之弹窗$ionicPopup
- 由星座判断引发我对vue.js的思考问题的模式的基本启示
- MySQL之修改数据表操作
- Codeforces Round #431 (Div. 2) 848A From Y to Y(思维)
- 洛谷p3387 拓扑+tarjan缩点
- 案例分享:如何通过JVM crash 的日志和core dump定位和分析Instrument引起的JVM crash
- 开发者需要的 9 款代码比较工具
- 测试
- 动态规划-试题(4)-转移罪犯
- 二分查找及插值查找
- C#基础-045 练习题
- SQL Server 触发器