CodeChef August Lunchtime 2014 题解
给一个由a和b两种类型的字符组成的字符串,每次可以从中选取任意长度的回文子序列(不一定连续)并删除。问最少需要几次能将整个字符串为空。
思路:如果本身是个回文串,那么只需要一次,否则需要两次(第一次选全部的a,第二次全部选b)。
Accepted Code:
def is_palidrome(s):
n = len(s);
for i in xrange(n / 2):
if s[i] != s[n - i - 1]:
return False;
return True; if __name__ == '__main__':
T = int(input())
while T:
T -= 1;
H = raw_input();
print 1 if is_palidrome(H) else 2;
知识点:给出公式:ind = (A * ind + B) % M,求其循环节长度。从公式可以看出,循环节不超过M。
另外,这题精度也是个坑,可以手动输出:".5"和".0"。
Accepted Code:
/*************************************************************************
> File Name: WALL.cpp
> Author: Stomach_ache
> Mail: sudaweitong@gmail.com
> Created Time: 2014年08月31日 星期日 19时16分49秒
> Propose:
************************************************************************/ #include <cmath>
#include <string>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <fstream>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
/*Let's fight!!!*/ const int MAX_M = ;
typedef long long LL;
LL IND[MAX_M], D[MAX_M], vis[MAX_M];
LL t, h, n, m, a, b, ind;
#define rep(i, n) for (int i = (0); i < (n); i++)
void seed(LL &ind) {
ind = (a * ind + b) % m;
} int main(void) {
ios::sync_with_stdio(false);
cin >> t;
while (t--) {
cin >> h >> n >> m >> a >> b >> ind;
rep (i, m) cin >> D[i]; int loop = ;
memset(vis, -, sizeof(vis));
vis[ind] = ;
IND[] = ind;
LL ans = ;
while (loop < n) {
ans += D[ind];
seed(ind);
if (vis[ind] != -) break;
vis[ind] = loop;
IND[loop] = ind;
++loop;
} if (loop <= n - ) {
LL sum = ;
for (int i = vis[ind]; i < loop; i++) sum += D[IND[i]];
LL times = (n - - loop) / (loop - vis[ind]);
ans += times * sum;
loop += times * (loop - vis[ind]);
loop++;
}
while (loop <= n - ) {
ans += D[ind];
seed(ind);
loop++;
} cout << ans * h / ;
if (ans * h % ) cout << ".5";
else cout << ".0";
cout << endl;
} return ;
}
待续。。。
待续。。。
CodeChef August Lunchtime 2014 题解的更多相关文章
- [转载]ECMA-262 6th Edition / Draft August 24, 2014 Draft ECMAScript Language Specification
http://people.mozilla.org/~jorendorff/es6-draft.html#sec-23.4 Draft Report Errors and Issues at: htt ...
- 「Codechef April Lunchtime 2015」Palindromeness
「Codechef April Lunchtime 2015」Palindromeness 解题思路 : 考虑对于回文子串 \(s\) 贡献的定义: \[ value_s = [\ s[1,\lflo ...
- codechef January Lunchtime 2017简要题解
题目地址https://www.codechef.com/LTIME44 Nothing in Common 签到题,随便写个求暴力交集就行了 Sealing up 完全背包算出得到长度≥x的最小花费 ...
- codechef January Challenge 2014 Sereja and Graph
题目链接:http://www.codechef.com/JAN14/problems/SEAGRP [题意] 给n个点,m条边的无向图,判断是否有一种删边方案使得每个点的度恰好为1. [分析] 从结 ...
- Codechef Not a Triangle题解
找出一个数组中的三个数,三个数不能组成三角形. 三个数不能组成三角形的条件是:a + b < c 两边和小于第三边. 这个问题属于三个数的组合问题了.暴力法可解,可是时间效率就是O(n*n*n) ...
- Codechef March Challenge 2014——The Street
The Street Problem Code: STREETTA https://www.codechef.com/problems/STREETTA Submit Tweet All submis ...
- CodeChef March Challenge 2019题解
传送门 \(CHNUM\) 显然正数一组,负数一组 for(int T=read();T;--T){ n=read(),c=d=0; fp(i,1,n)x=read(),x>0?++c:++d; ...
- CodeChef March Lunchtime 2018 div2
地址https://www.codechef.com/LTIME58B?order=desc&sortBy=successful_submissions 简单做了一下,前三题比较水,第四题应该 ...
- 【分块+树状数组】codechef November Challenge 2014 .Chef and Churu
https://www.codechef.com/problems/FNCS [题意] [思路] 把n个函数分成√n块,预处理出每块中各个点(n个)被块中函数(√n个)覆盖的次数 查询时求前缀和,对于 ...
随机推荐
- show master status
只有在主库上执行才能有效抵输出: 具体文档如下: # 在127.:3306主库上执行 tmp@127.0.0.1 ((none))> show variables like '%server%' ...
- MAC地址获取,有线网卡与无线网卡、物理网卡与虚拟网卡的区分
获取当前活跃状态的网卡MAC地址.物理地址 Wmic命令:Win32_NetworkAdapter和Win32_NetworkAdapterConfiguration. 其中cmd命令行执行: 1. ...
- [JZOJ6011] 【NOIP2019模拟1.25A组】天天爱跑步
题目 描述 题目大意 给你平面直角坐标系上的nnn个起点和nnn个终点,(x,y)(x,y)(x,y)每次只能走到(x,y+x)(x+y,y)(x,y−x)(x−y,y)(x,y+x)(x+y,y)( ...
- 网络编程(client发信息给server)
client发信息给server
- Python面向对象学习
以下面例子作为面向对象基础介绍,类比java里的面向对象既可以,大同小异 class Employee(): raiseAmount=1.04 employeeNum= def __init__(se ...
- VS2010-MFC(对话框:模态对话框及其弹出过程)
转自:http://www.jizhuomi.com/software/160.html 一.模态对话框和非模态对话框 Windows对话框分为两类:模态对话框和非模态对话框. 模态对话框是这样的对话 ...
- SpringBoot 01_HelloWorld
本文环境配置: JDK:1.8 开发工具:IDEA 操作系统:Windows10 集成工具:Maven SpringBoot版本:1.5.6.RELEASE 构件方式:Spring Initializ ...
- ES6之主要知识点(一)
引自:http://es6.ruanyifeng.com let 块级作用域 const 1.let let声明的变量只在它所在的代码块有效. for循环的计数器,就很合适使用let命令. var a ...
- springboot 2 修改端口号
springboot 废弃了EmbeddedServletContainerCustomizer ,修改端口,从官方文档上看到的方法, 1 import org.springframework.boo ...
- python configparser模块详解
此模块提供了一个实现基本配置语言的类 首先来看一个非常基本的配置文件,如下所示格式: [DEFAULT] ServerAliveInterval = 45 Compression = yes Comp ...