7
26
2018
1

恢复计划

一年多没写题了,暑假稍微恢复一下

现在大概是普及组水平

恢复一下

-------------------------------------------

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int a,b;

int main(){
freopen("1000.in","r",stdin);
freopen("1000.out","w",stdout);
scanf("%d %d",&a,&b);
printf("%d\n",a+b);
return 0;
}
#include<cstdio>
#include<set>
#include<algorithm>
using namespace std;

int n;
long long ans;
set<long long> St;
set<long long>::iterator I;

long long Abs(long long x){return x>0?x:-x;}
long long Min(long long x,long long y){return x<y?x:y;}

int main(){
freopen("1588.in","r",stdin);
freopen("1588.out","w",stdout);
scanf("%d",&n);
while(n--){
    long long sv,tp;
    scanf("%lld",&sv);
    if(St.empty()){St.insert(sv);ans=sv;}
    else {I=St.lower_bound(sv);tp=Abs(sv-*I);if(I!=St.begin())ans+=Min(tp,Abs(*--I-sv));else {ans+=tp;}St.insert(sv);}
}
printf("%lld\n",ans);
return 0;
}

正在恢复中...

Category: OI | Tags:

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com