Educational Codeforces Round 96 (Rated for Div. 2)C. Numbers on Whiteboard
Posted 尘封陌路
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Educational Codeforces Round 96 (Rated for Div. 2)C. Numbers on Whiteboard相关的知识,希望对你有一定的参考价值。
题目链接:https://codeforces.com/problemset/problem/1430/C
思路:(贪心)
1.一开始想的是头尾相加,结果是中间的值,后来发现不对,最优的方法应该是从后面最大的相加/2,最终答案都是2
AC代码:
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int a[N];
int ans;
int t,n;
int main()
cin>>t;
while(t--)
cin>>n;
cout<<"2"<<endl;
int last=n;
for(int i=n-1;i>=1;i--)
cout<<last<<" "<<i<<endl;
if((last+i)%2==0) last=(last+i)/2;
else last=(last+i)/2+1;
return 0;
以上是关于Educational Codeforces Round 96 (Rated for Div. 2)C. Numbers on Whiteboard的主要内容,如果未能解决你的问题,请参考以下文章
Educational Codeforces Round 7 A
Educational Codeforces Round 7
Educational Codeforces Round 90
Educational Codeforces Round 33