Codeforces 534A Exam 水

题意:给你1-n,问你最多能安排几个数相邻数字不相邻的位置。

解题思路:插空法。

解题代码:

 1 // File Name: a.cpp
 2 // Author: darkdream
 3 // Created Time: 2015年04月13日 星期一 00时00分57秒
 4
 5 #include<vector>
 6 #include<list>
 7 #include<map>
 8 #include<set>
 9 #include<deque>
10 #include<stack>
11 #include<bitset>
12 #include<algorithm>
13 #include<functional>
14 #include<numeric>
15 #include<utility>
16 #include<sstream>
17 #include<iostream>
18 #include<iomanip>
19 #include<cstdio>
20 #include<cmath>
21 #include<cstdlib>
22 #include<cstring>
23 #include<ctime>
24 #define LL long long
25
26 using namespace std;
27 int n ;
28 int main(){
29     scanf("%d",&n);
30     if(n == 1 || n== 2)
31     {
32         printf("1\n1\n");
33         return 0 ;
34     }
35     if(n == 3 )
36     {
37      printf("2\n1 3\n");
38      return 0 ;
39     }
40     if(n== 4)
41     {
42         printf("4\n3 1 4 2\n");
43         return 0 ;
44     }
45     if(n% 2== 0)
46     {
47       printf("%d\n",n);
48       for(int i = 1;i <= n/2 ;i ++)
49           printf("%d %d ",i,i+n/2);
50     }else{
51       printf("%d\n",n);
52       for(int i = 1;i <= n/2 ;i ++)
53           printf("%d %d ",i,i+n/2+1);
54       printf("%d\n",n/2+1);
55     }
56 return 0;
57 }

时间: 2024-11-12 02:48:27

Codeforces 534A Exam 水的相关文章

CodeForces 20B Equation 水题

题目链接:点击打开链接 #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <iostream> #include <map> #include <set> #include <math.h> using namespace std; #define inf 10000000 #define l

CodeForces 801D 计算几何,水

CodeForces 801D 题意:n个点的凸多边形,如果每个点都可在半径为 r的范围内移动,要保证仍为多边形,问 r最大为多少. tags:水题,练练手 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a;i<=b;i++) #define per(i,b,

CodeForces 705A Hulk (水题)

题意:输入一个 n,让你输出一行字符串. 析:很水题,只要判定奇偶性,输出就好. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring

codeforces 377A. Puzzles 水题

A. Puzzles Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/337/A Description The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to p

Codeforces 939A题水题

题目链接:http://codeforces.com/problemset/problem/939/A A题 A. Love Triangle time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output As you could know there are no male planes nor female planes. However

CodeForces 709A Juicer (水题, 模拟)

题意:给定 n 个桔子的大小,一个杯子的容积,一个最大限度,挨着挤桔子汁,如果大小大于限度,扔掉,如果不杯子满了倒掉,问你要倒掉多少杯. 析:直接按要求模拟就好,满了就清空杯子. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath&g

CodeForces 474A Keyboard (水题)

题意:给定一个键盘,然后一行字母,和一个字符,代表把那一行字母在键盘上左移还是右移一位. 析:没什么好说的,直接暴力就好. 代码如下: #include<bits/stdc++.h> using namespace std; typedef long long LL; char s1[] = "qwertyuiop"; char s2[] = "asdfghjkl;"; char s3[] = "zxcvbnm,./"; char s

CodeForces 474B Worms (水题,二分)

题意:给定 n 堆数,然后有 m 个话询问,问你在哪一堆里. 析:这个题是一个二分题,但是有一个函数,可以代替写二分,lower_bound. 代码如下: #include<bits/stdc++.h> using namespace std; typedef long long LL; const int maxn = 1e5 + 5; int a[maxn]; int main(){ int n, m; cin >> n; for(int i = 1; i <= n; +

CodeForces 513A Game (水题,博弈)

题意:两个人有n1,n2个球,然后分别最多拿出 k1,k2个球,然后扔掉,谁先拿完谁输. 析:很简单么,每人都足够聪明,就每次扔一个好了,那么,谁的球多,谁就能赢呗,如果相等,那么第一个扔的输. 代码如下: #include <iostream> #include <cstdio> using namespace std; int main(){ int n, m, k, l; cin >> n >> m >> k >> l; if(