博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #469 (Div. 2)
阅读量:4491 次
发布时间:2019-06-08

本文共 4639 字,大约阅读时间需要 15 分钟。

C. Zebras
time limit per test1 second
memory limit per test512 megabytes
inputstandard input
outputstandard output
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not.
Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days.
Input
In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters.
Output
If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≤ k ≤ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer li (1 ≤ li ≤ |s|), which is the length of the i-th subsequence, and then li indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1.
Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k.
Examples
inputCopy
0010100
output
3
3 1 3 4
3 2 5 6
1 7
inputCopy
111
output

-1

题意:把一串字符分成0,010,01010,0101010........

#include#include
#include
#include
#include
#include
#include
#include
#include
#include
#define inf 0x3f3f3f#define ll long long#define maxn 200005using namespace std;string s;int ans;vector
v[maxn];int main(){ cin>>s;ans=0;int flag=0; for(int i=0;i
D. A Leapfrog in the Array
time limit per test2 seconds
memory limit per test512 megabytes
inputstandard input
outputstandard output
Dima is a beginner programmer. During his working process, he regularly has to repeat the following operation again and again: to remove every second element from the array. One day he has been bored with easy solutions of this problem, and he has come up with the following extravagant algorithm.
Let's consider that initially array contains n numbers from 1 to n and the number i is located in the cell with the index 2i - 1 (Indices are numbered starting from one) and other cells of the array are empty. Each step Dima selects a non-empty array cell with the maximum index and moves the number written in it to the nearest empty cell to the left of the selected one. The process continues until all n numbers will appear in the first n cells of the array. For example if n = 4, the array is changing as follows:

http://codeforces.com/predownloaded/1e/83/1e838f4fb99d933b7259fbfe5b8722990c08d718.png

You have to write a program that allows you to determine what number will be in the cell with index x (1 ≤ x ≤ n) after Dima's algorithm finishes.
Input
The first line contains two integers n and q (1 ≤ n ≤ 1018, 1 ≤ q ≤ 200 000), the number of elements in the array and the number of queries for which it is needed to find the answer.
Next q lines contain integers xi (1 ≤ xi ≤ n), the indices of cells for which it is necessary to output their content after Dima's algorithm finishes.
Output
For each of q queries output one integer number, the value that will appear in the corresponding array cell after Dima's algorithm finishes.
Examples
inputCopy
4 3
2
3
4
output
3
2
4
inputCopy
13 4
10
5
4
8
output
13
3
8
9
Note
The first example is shown in the picture.
In the second example the final array is [1, 12, 2, 8, 3, 11, 4, 9, 5, 13, 6, 10, 7].

规律题。。

#include#include
#include
#include
#include
#include
#include
#include
#include
#include
#define inf 0x3f3f3f#define ll long long#define maxn 200005using namespace std;int main(){ ll n,m; cin>>n>>m; ll x; for(int i=0;i
>x; if(x>n) cout<<0<

转载于:https://www.cnblogs.com/da-mei/p/9053261.html

你可能感兴趣的文章
hdu1501 动态规划
查看>>
关于Microsoft app下同义词的整理
查看>>
EclipseADT编写单元测试代码的步骤
查看>>
Dart集合
查看>>
POJ 1988 Cube Stacking(并查集+路径压缩)
查看>>
黑马程序猿——JAVA高新技术——反射
查看>>
window.location.hash在firefox下中文自动转码为UTF-8问题
查看>>
Raspberry Pi 上使用GPU的OpenMax视频编码
查看>>
[LeetCode] Combinations 组合项
查看>>
95. Unique Binary Search Trees II
查看>>
js input框输入1位数字后自动跳到下一个input框聚焦
查看>>
我才知道爬虫也可以酱紫--火车采集器
查看>>
未来的物联网结点:可穿戴设备
查看>>
h5播放音乐
查看>>
Python 的內建模块
查看>>
每天一个linux命令(54):ping命令
查看>>
Centos下搭建FTP服务器基础笔记
查看>>
jpa-入门.缓存配置ehcache.xml
查看>>
krpano 常用标签
查看>>
21069207《Linux内核原理与分析》第四周作业
查看>>