本文共 1167 字,大约阅读时间需要 3 分钟。
Time Limit:3000MS | Memory Limit:60000K | |
Total Submissions:19016 | Accepted:7963 |
Description
Input
Output
Sample Input
710000-1
Sample Output
2018658
DP水题
#include#include using namespace std;const int MAXN = 9999999;int a[MAXN];bool flag[MAXN];void DP(){ for(int i=1;i<=500000;i++) { if(a[i-1] - i > 0 && flag[a[i-1] - i] == false) { a[i] = a[i-1] - i; flag[a[i-1] - i] = true; } else { a[i] = a[i-1] + i; flag[a[i-1] + i] = true; } }}int main(){ memset(flag,false,sizeof(false)); a[0] = 0; DP(); int k; while(cin>>k) { if(k == -1) break; cout< <
转载地址:http://etyhj.baihongyu.com/