Codeforces Round #233 (Div. 2)A(构造)

来源:互联网 发布:淘宝售假是什么意思 编辑:程序博客网 时间:2024/06/03 03:47

题目链接: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 DoubleQ    freopen("in.txt","r",stdin);    #endif    std::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;    }}


0 0
原创粉丝点击