Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

hash 844ms 写的比较挫

Posted by KatrineYang at 2016-08-22 01:27:56 on Problem 2081 and last updated at 2016-08-22 01:28:12
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator