编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#20995 #1022. jwp的排队难题 Compile Error 0 0 ms 0 K C++ 11 / 1020 B zichengsaber 2019-09-16 22:49:40
显示原始代码
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

typedef long long ll;
//面向对象学习
class Person {
public:
    ll a, b;
    Person(ll i, ll j) : a(i), b(j) {}
    Person() {}
    friend bool operator<(const Person &A, const Person &B) { return (B.a * A.b < A.a * B.b); }
};
ll minSum = 0, time = 0;
const int maxn = 1e5 + 5;
Person person[maxn];

/* 解决思想:
贪心的思想:题目的特点
1.总共等待的时间是一定的
2.贪心的直觉是先排ai/bi大的即单位等待时间内暴躁值更大的在前面
3.通过JM的介绍可以用相邻交换法证明其正确性
 */

int main() {
    int n, a, b;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        cin >> a >> b;
        person[i].a = a;
        person[i].b = b;
    }
    // sort
    sort(person + 1, person + 1 + n);
    //
    for (int i = 1; i <= n; i++) {
        time += person[i].b;
        minSum += person[i].a * time;
    }
    //
    cout << minSum;
    return 0;
}

编译信息

/sandbox/1/a.cpp:17:13: error: 'll time' redeclared as different kind of symbol
 ll minSum=0,time=0;
             ^~~~
In file included from /usr/include/pthread.h:24,
                 from /usr/include/x86_64-linux-gnu/c++/8/x32/bits/gthr-default.h:35,
                 from /usr/include/x86_64-linux-gnu/c++/8/x32/bits/gthr.h:148,
                 from /usr/include/c++/8/ext/atomicity.h:35,
                 from /usr/include/c++/8/bits/ios_base.h:39,
                 from /usr/include/c++/8/ios:42,
                 from /usr/include/c++/8/ostream:38,
                 from /usr/include/c++/8/iostream:39,
                 from /sandbox/1/a.cpp:1:
/usr/include/time.h:75:15: note: previous declaration 'time_t time(time_t*)'
 extern time_t time (time_t *__timer) __THROW;
               ^~~~
/sandbox/1/a.cpp: In function 'int main()':
/sandbox/1/a.cpp:41:13: warning: pointer to a function used in arithmetic [-Wpointer-arith]
         time+=person[i].b;
         ~~~~^~~~~~~~~~~~~
/sandbox/1/a.cpp:41:25: error: assignment of read-only location 'time'
         time+=person[i].b;
                         ^
/sandbox/1/a.cpp:42:28: error: invalid operands of types 'll' {aka 'long long int'} and 'time_t(time_t*) throw ()' {aka 'long long int(long long int*)'} to binary 'operator*'
         minSum+=person[i].a*time;
                 ~~~~~~~~~~~^~~~~
/sandbox/1/a.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~