本文主要是介绍Codeforces Round #233 (Div. 2)A(构造),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目链接:http://codeforces.com/contest/399/problem/A
解题思路:
构造出来即可,考虑p-k和p+k两个边界分别于1和n作比较,对左右符号特殊处理。
完整代码:
#include <algorithm>
#include <iostream>
#include <cstring>
#include <complex>
#include <cstdio>
#include <string>
#include <cmath>
using namespace std;
typedef long long LL;
const int MOD = int(1e9)+7;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1.0); //M_PI;int main()
{#ifdef DoubleQfreopen("in.txt","r",stdin);#endifstd::ios::sync_with_stdio(false);std::cin.tie(0);int n , p , k;while(cin >> n >> p >> k){int l = p - k;int r = p + k;int flag1 = 0 , flag2 = 0;if(l <= 1){flag1 = 1;if(l < 1)l = 1;}if(r >= n){flag2 = 1;if(r > n)r = n;}if(flag1 == 0)cout << "<<";for(int i = l ; i < p ; i ++)cout << " " << i;cout << " (" << p << ")";for(int i = p + 1 ; i <= r ; i ++)cout << " " << i;if(flag2 == 0)cout << " " << ">>";cout << endl;}
}
这篇关于Codeforces Round #233 (Div. 2)A(构造)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!