A题

给一个由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;

B题

知识点:给出公式: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 ;
}

C题

待续。。。

D题

待续。。。

CodeChef August Lunchtime 2014 题解的更多相关文章

  1. [转载]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 ...

  2. 「Codechef April Lunchtime 2015」Palindromeness

    「Codechef April Lunchtime 2015」Palindromeness 解题思路 : 考虑对于回文子串 \(s\) 贡献的定义: \[ value_s = [\ s[1,\lflo ...

  3. codechef January Lunchtime 2017简要题解

    题目地址https://www.codechef.com/LTIME44 Nothing in Common 签到题,随便写个求暴力交集就行了 Sealing up 完全背包算出得到长度≥x的最小花费 ...

  4. codechef January Challenge 2014 Sereja and Graph

    题目链接:http://www.codechef.com/JAN14/problems/SEAGRP [题意] 给n个点,m条边的无向图,判断是否有一种删边方案使得每个点的度恰好为1. [分析] 从结 ...

  5. Codechef Not a Triangle题解

    找出一个数组中的三个数,三个数不能组成三角形. 三个数不能组成三角形的条件是:a + b < c 两边和小于第三边. 这个问题属于三个数的组合问题了.暴力法可解,可是时间效率就是O(n*n*n) ...

  6. Codechef March Challenge 2014——The Street

    The Street Problem Code: STREETTA https://www.codechef.com/problems/STREETTA Submit Tweet All submis ...

  7. 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; ...

  8. CodeChef March Lunchtime 2018 div2

    地址https://www.codechef.com/LTIME58B?order=desc&sortBy=successful_submissions 简单做了一下,前三题比较水,第四题应该 ...

  9. 【分块+树状数组】codechef November Challenge 2014 .Chef and Churu

    https://www.codechef.com/problems/FNCS [题意] [思路] 把n个函数分成√n块,预处理出每块中各个点(n个)被块中函数(√n个)覆盖的次数 查询时求前缀和,对于 ...

随机推荐

  1. 内核下枚举进程 (二)ZwQuerySystemInformation

    说明: SYSTEM_INFORMATION_CLASS 的5号功能枚举进程信息.其是这个函数对应着ring3下的 NtQuerySystemInformation,但msdn上说win8以后ZwQu ...

  2. python库参考学习网址

    https://github.com/china-testing/python-api-tesing 这里有很多python库参考

  3. 洛谷 2197 nim游戏

    题目描述 甲,乙两个人玩Nim取石子游戏. nim游戏的规则是这样的:地上有n堆石子(每堆石子数量小于10000),每人每次可从任意一堆石子里取出任意多枚石子扔掉,可以取完,不能不取.每次只能从一堆里 ...

  4. input 的 placeholder 样式修改

    input::-webkit-input-placeholder{ color:#999999; } input::-moz-placeholder{ /* Mozilla Firefox 19+ * ...

  5. iOS7新特性-完美解决iOS7关于自定义导航条UIBarButtonItem偏移的问题

    前言: 本文由DevDiv社区@Vincent 原创,转载请注明出处! http://www.devdiv.com/iOS_iPhone-ios_ios_uibarbuttonitem_-thread ...

  6. PAT甲级题目1-10(C++)

    1001 A+B Format(20分) Calculate a+b and output the sum in standard format -- that is, the digits must ...

  7. .NET Framework的属性类对控件的支持功能

     ToolBoxItem 此属性为类特性.属于工具箱属性,可以设置当前控件是否在工具箱中显示,以及所在工具箱项的类型名称等信息.默认生成的控件都显示在工具箱中. 更多设计时属性介绍: 4.3 属性的 ...

  8. DOS批处理脚本

    先概述一下批处理是个什么东东.批处理的定义,至今我也没能给出一个合适的----众多高手们也都没给出----反正我不知道----看了我也不一定信服----我是个菜鸟,当然就更不用说了:但我想总结出一个“ ...

  9. springboot-actuator监控的401无权限访问

    在pom.xml里边添加 <dependency> <groupId>org.springframework.boot</groupId> <artifact ...

  10. 测试List对象排序

    实体类: package test; public class NightlyRate { private String rate; public String getRate() { return ...