cin/cout有毒,scanf/printf才是王道

###****cin/cout****
```c++
评测结果
编译成功

测试数据 #0: Accepted, time = 0 ms, mem = 5260 KiB, score = 10
测试数据 #1: Accepted, time = 15 ms, mem = 5256 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 5260 KiB, score = 10
测试数据 #3: Accepted, time = 31 ms, mem = 5252 KiB, score = 10
测试数据 #4: Accepted, time = 62 ms, mem = 5256 KiB, score = 10
测试数据 #5: Accepted, time = 203 ms, mem = 5260 KiB, score = 10
测试数据 #6: Accepted, time = 265 ms, mem = 5256 KiB, score = 10
测试数据 #7: Accepted, time = 531 ms, mem = 5256 KiB, score = 10
测试数据 #8: Accepted, time = 609 ms, mem = 5256 KiB, score = 10
测试数据 #9: TimeLimitExceeded, time = 1015 ms, mem = 5248 KiB, score = 0
TimeLimitExceeded, time = 2731 ms, mem = 5260 KiB, score = 90
代码
#include <iostream>
#include <algorithm>
using namespace std;
struct swiss {
int num,w,s;
}Athlete[200001],win[100001],lose[100001];
inline bool cmp(swiss x,swiss y) {
if(x.s != y.s) return x.s > y.s;
else return x.num < y.num;
}
int main() {
//ifstream cin("swiss.in",ios :: in);
//ofstream cout("swiss.out",ios :: out);
int n,r,q;
cin >> n >> r >> q;
for (int i = 0;i < 2*n;i++) {
Athlete[i].num = i+1;
cin >> Athlete[i].s;
}
for (int i = 0;i < 2*n;i++)
cin >> Athlete[i].w;
sort(Athlete,Athlete+2*n,cmp);
while (r--) {
for (int j = 0,k = 0;j < 2*n;j += 2,k++) {
if (Athlete[j].w > Athlete[j+1].w) {
Athlete[j].s++;
win[k] = Athlete[j];
lose[k] = Athlete[j+1];
} else {
Athlete[j+1].s++;
win[k] = Athlete[j+1];
lose[k] = Athlete[j];
}
}
merge(win,win+n,lose,lose+n,Athlete,cmp);
}
cout << Athlete[q-1].num;
return 0;
}

```

###****scanf/printf****
```c++
评测结果
编译成功

测试数据 #0: Accepted, time = 0 ms, mem = 5256 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 5252 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 5248 KiB, score = 10
测试数据 #3: Accepted, time = 15 ms, mem = 5252 KiB, score = 10
测试数据 #4: Accepted, time = 46 ms, mem = 5256 KiB, score = 10
测试数据 #5: Accepted, time = 140 ms, mem = 5256 KiB, score = 10
测试数据 #6: Accepted, time = 187 ms, mem = 5252 KiB, score = 10
测试数据 #7: Accepted, time = 359 ms, mem = 5252 KiB, score = 10
测试数据 #8: Accepted, time = 421 ms, mem = 5256 KiB, score = 10
测试数据 #9: Accepted, time = 390 ms, mem = 5256 KiB, score = 10
Accepted, time = 1558 ms, mem = 5256 KiB, score = 100
代码
#include <iostream>
#include <algorithm>
using namespace std;
struct swiss {
int num,w,s;
}Athlete[200001],win[100001],lose[100001];
inline bool cmp(swiss x,swiss y) {
if(x.s != y.s) return x.s > y.s;
else return x.num < y.num;
}
int main() {
//ifstream cin("swiss.in",ios :: in);
//ofstream cout("swiss.out",ios :: out);
ios :: sync_with_stdio(false);
int n,r,q;
cin >> n >> r >> q;
for (int i = 0;i < 2*n;i++) {
Athlete[i].num = i+1;
cin >> Athlete[i].s;
}
for (int i = 0;i < 2*n;i++)
cin >> Athlete[i].w;
sort(Athlete,Athlete+2*n,cmp);
while (r--) {
for (int j = 0,k = 0;j < 2*n;j += 2,k++) {
if (Athlete[j].w > Athlete[j+1].w) {
Athlete[j].s++;
win[k] = Athlete[j];
lose[k] = Athlete[j+1];
} else {
Athlete[j+1].s++;
win[k] = Athlete[j+1];
lose[k] = Athlete[j];
}
}
merge(win,win+n,lose,lose+n,Athlete,cmp);
}
cout << Athlete[q-1].num;
return 0;
}
```

1 条评论

  • @ 2016-09-11 14:56:19

    ios::sync_with_stdio(false); 可以解决问题

    • @ 2016-09-12 13:15:17

      哦,谢谢

    • @ 2016-09-12 13:15:22
      评测结果
      编译成功
      
      测试数据 #0: Accepted, time = 0 ms, mem = 5256 KiB, score = 10
      测试数据 #1: Accepted, time = 0 ms, mem = 5252 KiB, score = 10
      测试数据 #2: Accepted, time = 0 ms, mem = 5248 KiB, score = 10
      测试数据 #3: Accepted, time = 15 ms, mem = 5252 KiB, score = 10
      测试数据 #4: Accepted, time = 46 ms, mem = 5256 KiB, score = 10
      测试数据 #5: Accepted, time = 140 ms, mem = 5256 KiB, score = 10
      测试数据 #6: Accepted, time = 187 ms, mem = 5252 KiB, score = 10
      测试数据 #7: Accepted, time = 359 ms, mem = 5252 KiB, score = 10
      测试数据 #8: Accepted, time = 421 ms, mem = 5256 KiB, score = 10
      测试数据 #9: Accepted, time = 390 ms, mem = 5256 KiB, score = 10
      Accepted, time = 1558 ms, mem = 5256 KiB, score = 100
      代码
      #include <iostream>
      #include <algorithm>
      using namespace std;
      struct swiss {
        int num,w,s;
      }Athlete[200001],win[100001],lose[100001];
      inline bool cmp(swiss x,swiss y) {
        if(x.s != y.s) return x.s > y.s;
        else return x.num < y.num;
      }
      int main() {
        //ifstream cin("swiss.in",ios :: in);
        //ofstream cout("swiss.out",ios :: out);
        ios :: sync_with_stdio(false);
        int n,r,q;
        cin >> n >> r >> q;
        for (int i = 0;i < 2*n;i++) {
          Athlete[i].num = i+1;
          cin >> Athlete[i].s;
        }
        for (int i = 0;i < 2*n;i++)
          cin >> Athlete[i].w;
        sort(Athlete,Athlete+2*n,cmp);
        while (r--) {
          for (int j = 0,k = 0;j < 2*n;j += 2,k++) {
            if (Athlete[j].w > Athlete[j+1].w) {
              Athlete[j].s++;
              win[k] = Athlete[j];
              lose[k] = Athlete[j+1];
            } else {
              Athlete[j+1].s++;
              win[k] = Athlete[j+1];
              lose[k] = Athlete[j];
            }
          }
          merge(win,win+n,lose,lose+n,Athlete,cmp);
        }
        cout << Athlete[q-1].num;
        return 0;
      }
      
  • 1

信息

ID
1771
难度
7
分类
模拟 | 数据结构 | 队列 点击显示
标签
递交数
3535
已通过
703
通过率
20%
被复制
19
上传者