codeforces 399A. Pages(模拟题,细心点就能AC)

2023-11-08 11:48

本文主要是介绍codeforces 399A. Pages(模拟题,细心点就能AC),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1、http://codeforces.com/problemset/problem/399/A

2、题目

A. Pages
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are n pages numbered by integers from 1 to n. Assume that somebody is on the p-th page now. The navigation will look like this:

<< p - k p - k + 1 ... p - 1 (p) p + 1 ... p + k - 1 p + k >>

When someone clicks the button "<<" he is redirected to page 1, and when someone clicks the button ">>" he is redirected to page n. Of course if someone clicks on a number, he is redirected to the corresponding page.

There are some conditions in the navigation:

  • If page 1 is in the navigation, the button "<<" must not be printed.
  • If page n is in the navigation, the button ">>" must not be printed.
  • If the page number is smaller than 1 or greater than n, it must not be printed.
 

You can see some examples of the navigations. Make a program that prints the navigation.

Input

The first and the only line contains three integers n, p, k (3 ≤ n ≤ 100; 1 ≤ p ≤ n; 1 ≤ k ≤ n)

Output

Print the proper navigation. Follow the format of the output from the test samples.

Sample test(s)
Input
17 5 2
Output
<< 3 4 (5) 6 7 >> 
Input
6 5 2
Output
<< 3 4 (5) 6 
Input
6 1 2
Output
(1) 2 3 >> 
Input
6 2 2
Output
1 (2) 3 4 >>
Input
9 6 3
Output
<< 3 4 5 (6) 7 8 9
Input
10 6 3
Output
<< 3 4 5 (6) 7 8 9 >>
Input
8 5 4
Output
1 2 3 4 (5) 6 7 8 

3、AC代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{int n,p,k;while(scanf("%d%d%d",&n,&p,&k)!=EOF){int s=p-k;int e=p+k;if(p==1){printf("(1) ");int flag=0;for(int i=2;i<=e;i++){if(i<n)printf("%d ",i);else if(i==n){printf("%d ",i);flag=1;break;}}if(flag==0){printf(">> \n");}elseprintf("\n");}else{if(s<=1){int flag=0;for(int i=1;i<=e;i++){if(i==p){printf("(%d) ",i);if(i==n)flag=1;}else if(i<n){printf("%d ",i);}else if(i==n){printf("%d ",i);flag=1;break;}}if(flag==0)printf(">> \n");elseprintf("\n");}else{int flag=0;printf("<< ");for(int i=s;i<=e;i++){if(i==p){printf("(%d) ",i);if(i==n)flag=1;}else if(i<n)printf("%d ",i);else if(i==n){printf("%d ",n);flag=1;//printf("*%d\n",flag);break;}}if(flag==0)printf(">> \n");elseprintf("\n");}}}return 0;
}
/*
100 100 17
*/


 

这篇关于codeforces 399A. Pages(模拟题,细心点就能AC)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/369646

相关文章

hdu 3065 AC自动机 匹配串编号以及出现次数

题意: 仍旧是天朝语题。 Input 第一行,一个整数N(1<=N<=1000),表示病毒特征码的个数。 接下来N行,每行表示一个病毒特征码,特征码字符串长度在1—50之间,并且只包含“英文大写字符”。任意两个病毒特征码,不会完全相同。 在这之后一行,表示“万恶之源”网站源码,源码字符串长度在2000000之内。字符串中字符都是ASCII码可见字符(不包括回车)。

Codeforces Round #240 (Div. 2) E分治算法探究1

Codeforces Round #240 (Div. 2) E  http://codeforces.com/contest/415/problem/E 2^n个数,每次操作将其分成2^q份,对于每一份内部的数进行翻转(逆序),每次操作完后输出操作后新序列的逆序对数。 图一:  划分子问题。 图二: 分而治之,=>  合并 。 图三: 回溯:

zoj 3228 ac自动机

给出一个字符串和若干个单词,问这些单词在字符串里面出现了多少次。单词前面为0表示这个单词可重叠出现,1为不可重叠出现。 Sample Input ab 2 0 ab 1 ab abababac 2 0 aba 1 aba abcdefghijklmnopqrstuvwxyz 3 0 abc 1 def 1 jmn Sample Output Case 1 1 1 Case 2

Codeforces Round #261 (Div. 2)小记

A  XX注意最后输出满足条件,我也不知道为什么写的这么长。 #define X first#define Y secondvector<pair<int , int> > a ;int can(pair<int , int> c){return -1000 <= c.X && c.X <= 1000&& -1000 <= c.Y && c.Y <= 1000 ;}int m

Codeforces Beta Round #47 C凸包 (最终写法)

题意慢慢看。 typedef long long LL ;int cmp(double x){if(fabs(x) < 1e-8) return 0 ;return x > 0 ? 1 : -1 ;}struct point{double x , y ;point(){}point(double _x , double _y):x(_x) , y(_y){}point op

Codeforces Round #113 (Div. 2) B 判断多边形是否在凸包内

题目点击打开链接 凸多边形A, 多边形B, 判断B是否严格在A内。  注意AB有重点 。  将A,B上的点合在一起求凸包,如果凸包上的点是B的某个点,则B肯定不在A内。 或者说B上的某点在凸包的边上则也说明B不严格在A里面。 这个处理有个巧妙的方法,只需在求凸包的时候, <=  改成< 也就是说凸包一条边上的所有点都重复点都记录在凸包里面了。 另外不能去重点。 int

D4代码AC集

贪心问题解决的步骤: (局部贪心能导致全局贪心)    1.确定贪心策略    2.验证贪心策略是否正确 排队接水 #include<bits/stdc++.h>using namespace std;int main(){int w,n,a[32000];cin>>w>>n;for(int i=1;i<=n;i++){cin>>a[i];}sort(a+1,a+n+1);int i=1

Codeforces 482B 线段树

求是否存在这样的n个数; m次操作,每次操作就是三个数 l ,r,val          a[l] & a[l+1] &......&a[r] = val 就是区间l---r上的与的值为val 。 也就是意味着区间[L , R] 每个数要执行 | val 操作  最后判断  a[l] & a[l+1] &......&a[r] 是否= val import ja

机试算法模拟题 服务中心选址

题目描述 一个快递公司希望在一条街道建立新的服务中心。公司统计了该街道中所有区域在地图上的位置,并希望能够以此为依据为新的服务中心选址:使服务中心到所有区域的距离的总和最小。 给你一个数组positions,其中positions[i] = [left, right] 表示第 i 个区域在街道上的位置,其中left代表区域的左侧的起点,right代表区域的右侧终点,假设服务中心的位置为loca

Codeforces Round 971 (Div. 4) (A~G1)

A、B题太简单,不做解释 C 对于 x y 两个方向,每一个方向至少需要 x / k 向上取整的步数,取最大值。 由于 x 方向先移动,假如 x 方向需要的步数多于 y 方向的步数,那么最后 y 方向的那一步就不需要了,答案减 1 代码 #include <iostream>#include <algorithm>#include <vector>#include <string>