记录编号 |
116118 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[HNOI 2004] 宠物收养所 |
最终得分 |
100 |
用户昵称 |
HouJikan |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.346 s |
提交时间 |
2014-08-24 15:38:56 |
内存使用 |
3.15 MiB |
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <ctime>
#include <iterator>
#include <functional>
#define pritnf printf
#define scafn scanf
#define For(i,j,k) for(int i=(j);i<=(k);(i)++)
using namespace std;
typedef long long LL;
typedef unsigned int Uint;
const int INF=0x7ffffff;
//==============struct declaration==============
//==============var declaration=================
int nowk;
LL sum=0;
int cnt=1;
set <int> special;
//==============function declaration============
//==============main code=======================
int main()
{
string FileName="pet";//程序名
string FloderName="COGS";//文件夹名
freopen((FileName+".in").c_str(),"r",stdin);
freopen((FileName+".out").c_str(),"w",stdout);
#ifdef DEBUG
system(("cp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\standard.cpp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\submit.txt").c_str());
#endif
int n,a,b;
set<int>::iterator it1,it2;
special.clear();
scanf("%d",&n);
scanf("%d%d",&nowk,&a);
special.insert(a);
For(i,2,n)
{
scanf("%d%d",&a,&b);
if (a==nowk||cnt==0)
{
if (cnt==0)
nowk=a;
special.insert(b);
cnt++;
}
else
{
it2=special.lower_bound(b);
int y=(*it2);
if (it2==special.begin())
{
special.erase(y);
sum+=abs(y-b);
//printf("person %d: %d\n",i,y);
cnt--;sum=sum%1000000;
continue;
}
if (it2==special.end())
{
int x=(*(--it2));
special.erase(x);
//printf("person %d: %d\n",i,x);
cnt--;sum+=abs(x-b);
sum=sum%1000000;
continue;
}
int x=(*(--it2));
if (abs(x-b)<=abs(y-b))
{
special.erase(x);
sum+=abs(x-b);
//printf("person %d: %d\n",i,x);
}
else
{
special.erase(y);
sum+=abs(y-b);
//printf("person %d: %d\n",i,y);
}
cnt--;sum=sum%1000000;
}
}
printf("%d\n",sum);
return 0;
}
//================fuction code====================