救命……救命……首尾AC,其他全部WA 救命……

P1678 烦恼的高考志愿

guanchen @ 2019-11-12 19:17:47

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int cg[100001],sg[100001];
int main()
{
    int m,n;
    int sum=0,k=1;
    int ans=1;
    cin>>m>>n;
    for(int i=1;i<=m;i++)
        cin>>cg[i];

    for(int i=1;i<=n;i++)
        cin>>sg[i];

    sort(cg+1,cg+m+1);
    sort(sg+1,sg+n+1);

    int lan=n;
    for(int i=1;i<=n;i++)
    {
        while(abs(cg[i]-sg[k])<abs(cg[i+1]-sg[k])){
                sum+=(abs(cg[i]-sg[k]));
                k++;    
                lan--;}
    }

    cout<<sum;
    return 0;
}

by gaochenglong @ 2019-11-12 19:23:57

#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n = 0,m = 0;
    cin >> n >> m;

    vector <int> c;

    c.resize(n + 1);

    for(int i = 1;i <= n;i++)
    {
        cin >> c[i];
    }

    sort(c.begin(),c.end());
//  sort(p.begin(),p.end());

    int cnt = 0;

    for(int i = 1;i <= m;i++)
    {
//      int a = *lower_bound(c.begin(),c.end(),p[i])--;
//      int b = *lower_bound(c.begin(),c.end(),p[i]);
//      int d = *lower_bound(c.begin(),c.end(),p[i]);
//      
//      cnt += min(abs(a - p[i]),min(abs(b - p[i]),abs(d - p[i])));
//      cout << min(abs(a - p[i]),min(abs(b - p[i]),abs(d - p[i]))) << " " << a << " " << b  << " " << d<< endl;

        int p;
        cin >> p;

        int x = lower_bound(c.begin(),c.end(),p) - c.begin();

/** TODO:特判 */

    }
    cout << cnt;

    return 0;
}

by guanchen @ 2019-11-12 19:29:03

@gaojunce 用函数,是一种猥琐的行为


by guanchen @ 2019-11-12 19:29:22

@gaojunce (因为我不会)


by xwmwr @ 2019-11-12 19:38:55

对不起,我们尽力了


|