第一份代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 10 , MAXM = 2025;
int n;
int cnt;
struct Node {
int p , t;
};
Node a[MAXM];
bool flag[MAXN];
inline bool cmp(Node a , Node b) {
return a.t < b.t;
}
signed main() {
freopen("P1413_2.in" , "r" , stdin);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for(register int i = 1;i <= n;i ++)
cin >> a[i].p >> a[i].t;
sort(a + 1 , a + 1 + n , cmp);
for(register int i = 1;i <= n;i ++) {
if(flag[i])
continue;
++ cnt;
cout << cnt << " ";
for(register int j = 1;j <= n;j ++)
if(a[j].p == a[i].p && a[j].t < a[i].t + 60 && !flag[j])
flag[j] = true;
}
cout << cnt;
return 0;
}
第二份代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 10 , MAXM = 2025;
int n;
struct Node {
int p , t;
};
Node a[MAXM];
bool flag[MAXN];
int cnt;
inline bool cmp(Node a , Node b) {
return a.t < b.t;
}
signed main() {
freopen("P1413_2.in" , "r" , stdin);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for(register int i = 1;i <= n;i ++)
cin >> a[i].p >> a[i].t;
sort(a + 1 , a + 1 + n , cmp);
for(register int i = 1;i <= n;i ++) {
if(flag[i])
continue;
++ cnt;
cout << cnt << " ";
for(register int j = 1;j <= n;j ++)
if(a[j].p == a[i].p && a[j].t < a[i].t + 60 && !flag[j])
flag[j] = true;
}
cout << cnt;
return 0;
}
唯一的不同点是 cnt
的定义位置变了,为什么输出也变了?