[CodeForces950C]Zebras】的更多相关文章

Description 题目地址: Codeforces 题意:给你一串只含01的字符串,判断能否将字符串分为k个子序列,使得子序列满足以下条件: 开头和结尾都是0 相邻的2个数是01或者10 如0, 010, 01010 是合法的,1, 0110, 0101不合法 要求输出方案 (k可以为任意正整数,评测用SPJ) Solution 我们发现,0可以单独为一组,那么只要匹配完所有的1剩下的0全单独算就行了 对于方案可以用vector储存,关键在于如何划分子序列 开一个指针变量p和一个方案数cn…
C. Zebras time limit per test memory limit per test 512 megabytes input standard input output standard 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 …
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 d…
http://codeforces.com/contest/950/problem/C 题意: 给出一个01序列,问能否将这个序列分为若干个0开头0结尾的序列 输出方案 如果有解,几个1能在一个序列就在一个序列 一定可以找到解 因为0可以单独1个序列,1必须要依托于0 2个1如果分开 要4个0,连起来要3个0 暴力的做法就是: 如果当前是0,扫一遍已有序列,如果有1结尾的就把这个0放到那个1的后面 没有以1结尾的序列,新建一个序列 如果当前是1,扫一遍已有序列,如果有0结尾的就把这个1放到那个0…
题意:给你一个01串,问其是否能拆成若干形如0101010的子串,若能,输出所有子串的0,1 的位置. 题解:一开是暴力,然后瞎找规律, 最后找到一种神奇的线性构造法:扫一遍字符串,若为0就一直竖着往下写0,碰到1就回头往上写,再碰到0 就回头往下写······判断无法构造的依据:如果写1写得超过了上界就跳出,如果最后写的0不在最下面也跳出//codeforces上看到的一段代码秀的脑壳疼 坑:之前随便找规律,写了个巨丑的代码,逻辑混乱,直接wa掉. 无脑写的直接T了 ac #define _C…
借鉴自: https://www.cnblogs.com/SuuT/p/8619227.html https://blog.csdn.net/my_sunshine26/article/details/79502152 题意: 给定一个01字符串,需要你把它分为k个子序列,其中k可以为任意正整数. 对子序列的要求为 以0开始,以0结束 0,1相间 输出满足条件的一种结果即可.  输出的结果还要从低到高的顺序 扫一遍字符串,若为0就一直竖着往下写0,碰到1就回头往上写,再碰到0 就回头往下写···…
题意 0, 010, 01010 这一类的01交替且开头和结尾都为0的序列被称为zebra序列.给出一段01序列,尝试能否把他分为k个子序列使得每个子序列都是zebra序列. 分析 这个题应该算是水题把,但是确实把我卡了. 一开始暴力找在序列中找1,然后分别往前往后各找一个0.但是最坏情况到O(n^2),TLE在第八组.然后我尝试了各种Set,vector,二分之类的瞎搞结果一直都没把复杂度降下来一直T在第八组绝望了. 赛后看其他人的代码发现··可以O(n)扫一遍,当s[i]是0的时候找加入最后…
思路: 贪心乱搞. 实现: #include <bits/stdc++.h> using namespace std; vector<vector<int>> v; int main() { string s; while (cin >> s) { set<int> x, y; ; i < v.size(); i++) v[i].clear(); bool no_ans = false; ; i < s.length(); i++)…
是一道不错的构造题. 我们观察,一个 111 的前后必须都有 000. 那么,我们开一个二维数组 (vector)(vector)(vector),这样每遇到一个 000 就将 000 加入到当前的 G[cnt]G[cnt]G[cnt] 中,并 ++cntcntcnt, 这样满足的性质是 kkk 到 cntcntcnt 的所有状态都是已 111 结尾的(或者为空),以此来判断是否有解. Code: #include<cstdio> #include<vector> #include…
题意 : 给出一个 01 串,要求你将其分隔出若干个子序列 ( 每个数字只能属于某一个子序列 ) ,子序列必须满足由 0 开头和结尾,且中间需 01 交替构成.若无法做到,则输出 -1. 分析 :  很容易想到需要去贪心配对 0 和 1 即 能 01 交替去构造就尽量选择这种方案,这样才能用更少的 0 去配对尽量多的 1 用 vector<int> idx[] 这个二维数组来装各个子序列的信息 使用两个 set 来装现在以 0 结尾以及以 1 结尾的子序列的下标 然后 O(n) 从左到右扫一遍…
作者:zhbzz2007 出处:http://www.cnblogs.com/zhbzz2007 欢迎转载,也请保留这段声明.谢谢! 1 模块简介 Python 3.5 增加了一个有意思的库--typing.这将会给Python增加了类型暗示.类型暗示是一种可以将你的函数变量声明为一种特定类型的声明.当然,类型暗示并不是绑定.它仅仅是暗示,所以这种机制并不能阻止工程师传入他们不应该传入的参数.这个就是Python.你可以在PEP 484中阅读类型暗示的说明,或者你也可以在PEP 483 阅读背后…
logging.basicConfig函数各参数: filename: 指定日志文件名 filemode: 和file函数意义相同,指定日志文件的打开模式,'w'或'a' format: 指定输出的格式和内容,format可以输出很多有用信息,如上例所示: %(levelno)s: 打印日志级别的数值 %(levelname)s: 打印日志级别名称 %(pathname)s: 打印当前执行程序的路径,其实就是sys.argv[0] %(filename)s: 打印当前执行程序名 %(funcNa…
引用js: <link rel="stylesheet" href="../jquery.mobile-1.1.0/jquery.mobile-1.1.0.css" /> <script src="../jquery.mobile-1.1.0/jquery-1.7.2.js"></script> <script src="../jquery.mobile-1.1.0/jquery.mobile-…
Python同时向控制台和文件输出日志logging的方法http://www.jb51.net/article/66756.htm 1 #-*- coding:utf-8 -*- 2 import logging 3 # 配置日志信息 4 logging.basicConfig(level=logging.DEBUG, 5 format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s', 6 datefmt='%m-%d %H:%M',…
2015-03-06   328   Unusual Data Types    ——You can carry this technique to extremes,putting all the variables in your program into one big,juicy variable and then passingit everywhere.Careful programmers avoid bundling data any more than is logically…
A. 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 da…
#-*- coding:utf-8 -*-import logging # 配置日志信息logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s', datefmt='%m-%d %H:%M', filename='myapp.log', filemode='w')# 定义一个Handler打印INFO及以上级别的日志到sys.stderrconsole…
logging 的配置和使用 reference : logging cookbook logging HOWTO 测试源码,example import logging nt = 'xwei' # logging.basicConfig(filename='log/log_test.log', # format='%(asctime)s, %(levelname)s:%(message)s', datefmt='%m/%d/%Y %I:%M:%S %p', # filemode='w', le…
剧毒比赛,至少涨了分对吧.: ( [A]Left-handers, Right-handers and Ambidexters 题意: 有\(l\)个右撇子,\(r\)个左撇子,\(a\)个双手都惯用的人. 要让他们组成两个队伍,一边用左手,一边用右手,这两个队伍人数要相同. 问最大人数. 题解: 随便搞…… #include<bits/stdc++.h> using namespace std; int l,r,a; int main(){ scanf("%d%d%d",…
C. Plasticine zebra time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spend…
水题 B - Minimum’s Revenge There is a graph of n vertices which are indexed from 1 to n. For any pair of different vertices, the weight of the edge between them is the least common multiple of their indexes. Mr. Frog is wondering about the total weight…
一.StreamHandler 流handler——包含在logging模块中的三个handler之一. 能够将日志信息输出到sys.stdout, sys.stderr 或者类文件对象(更确切点,就是能够支持write()和flush()方法的对象). 只有一个参数: class logging.StreamHandler(stream=None) 1 2 日志信息会输出到指定的stream中,如果stream为空则默认输出到sys.stderr. 二.FileHandler logging模…
1.简单的将日志打印到屏幕 import logging logging.debug('This is debug message')logging.info('This is info message')logging.warning('This is warning message') 屏幕上打印:WARNING:root:This is warning message 默认情况下,logging将日志打印到屏幕,日志级别为WARNING:日志级别大小关系为:CRITICAL > ERROR…
A. Left-handers, Right-handers and Ambidexters 题意 \(l\)个左撇子,\(r\)个右撇子,\(a\)个两手均可.要组成一支队伍,里面用左手的人数与用右手的人数相等,问队伍最大人数. Code #include <bits/stdc++.h> #define F(i, a, b) for (int i = (a); i < (b); ++i) #define F2(i, a, b) for (int i = (a); i <= (b)…
A. Left-handers, Right-handers and Ambidexters time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are at a water bowling training. There are l people who play with their left hand, r peopl…
Plasticine zebra time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending…
晚上比较懒,直接搬砖了. 1.简单的将日志打印到屏幕   import logging logging.debug('This is debug message') logging.info('This is info message') logging.warning('This is warning message') 屏幕上打印:WARNING:root:This is warning message 默认情况下,logging将日志打印到屏幕,日志级别为WARNING: 日志级别大小关系…
logging模块: https://docs.python.org/3/howto/logging.html#logging-basic-tutorial 本记录教程 日志记录是一种跟踪某些软件运行时发生的事件的方法.该软件的开发人员将日志调用添加到其代码中,以指示已发生某些事件.事件由描述性消息描述,该消息可以可选地包含变量数据(即,每次事件发生时都可能不同的数据).事件也具有开发者认为该事件的重要性.重要性也可以称为水平 或严重性. 当使用日志 日志记录提供了一组便利功能,用于简单的日志记…