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

秒杀,贴代妈

Posted by KatrineYang at 2016-09-01 02:42:04 on Problem 2282
#include <iostream>
#include <stdio.h>
using namespace std;

int a,b;

int p10[9] = {1,10,100,1000,10000,100000,1000000,10000000,100000000};

int intersect(int s1, int e1, int s2, int e2){
	int s = (s1>s2)? s1 : s2;
	int e = (e1<e2)? e1 : e2;
	if(s > e) return 0;
	return e-s+1;
}

int main() {

	while(1){
		scanf("%d%d", &a, &b);
		if(a == 0 && b == 0) return 0;
		if(a > b){
			int temp = a;
			a = b;
			b = temp;
		}
		int ans[10] = {0};
		for(int k = 1; k <= 8; k++){
			int t1 = a/p10[k], r1 = a%p10[k], t2 = b/p10[k], r2 = b%p10[k];
			//cout << t1 << " " << r1 << " " << t2 << " " << r2 << endl;
			if(t1 == t2){
				if(t1 != 0) ans[0] += intersect(0,p10[k-1]-1,r1,r2);
				for(int j = 1; j <= 9; j++) ans[j] += intersect(j*p10[k-1], (j+1)*p10[k-1]-1, r1, r2);
			}
			else{
				int zqjgs = t2-t1-1;
				for(int j = 0; j <= 9; j++) ans[j] += zqjgs * p10[k-1];
				if(t1!=0) ans[0] += intersect(0,p10[k-1]-1,r1,p10[k]-1);
				for(int j = 1; j <= 9; j++) ans[j] += intersect(j*p10[k-1],(j+1)*p10[k-1]-1, r1, p10[k]-1);
				for(int j = 0; j <= 9; j++) ans[j] += intersect(j*p10[k-1],(j+1)*p10[k-1]-1, 0, r2);
			}
		}
		for(int i = 0; i < 10; i++) cout << ans[i] << " ";
		cout << endl;
	}
	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