Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
hash 844ms 写的比较挫#include <iostream> #include <vector> #include <stdio.h> using namespace std; int a[500005]; vector<int> h[233333]; int main() { vector<int> q; int mx = 0; while(1){ int temp; scanf("%d", &temp); if(temp == -1) break; if(temp > mx) mx = temp; q.push_back(temp); } a[0] = 0; h[0].push_back(0); for(int i = 1; i <= mx; i++){ int jian = a[i-1]-i; if(jian < 0){ a[i] = a[i-1]+i; h[a[i]%233333].push_back(a[i]); } else{ int mod = jian%233333; int sz = h[mod].size(); bool find = 0; for(int j = 0; j < sz; j++){ if(h[mod][j] == jian){ find = 1; break; } } if(find){ a[i] = a[i-1]+i; h[a[i]%233333].push_back(a[i]); } else{ a[i] = jian; h[mod].push_back(a[i]); } } } int z = q.size(); for(int i = 0; i < z; i++){ printf("%d\n", a[q[i]]); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator