题目出处:http://codeforces.com/problemset/problem/903/A 题目大意就是:一个数能否用正整数个另外两个数合成 #include<iostream> using namespace std; //双重枚举 int main(){ int n;cin>>n; while(n--){ ; ; i</; i++){ ; j</; j++){ +j* == temp){ flag = ; break; }//本来想使用连续break发现…
A. Hungry Student Problem time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some frie…
Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the marks were one by one added…
题目链接:uva 10837 - A Research Problem 题目大意:给定一个phin.要求一个最小的n.欧拉函数n等于phin 解题思路:欧拉函数性质有,p为素数的话有phip=p−1;假设p和q互质的话有phip∗q=phip∗phiq 然后依据这种性质,n=pk11(p1−1)∗pk22(p2−1)∗⋯∗pkii(pi−1),将全部的pi处理出来.暴力搜索维护最小值,尽管看上去复杂度很高,可是由于对于垒乘来说,增长很快,所以搜索范围大大被缩小了. #include <cstdi…
You are given a string representing an attendance record for a student. The record only contains the following three characters: 'A' : Absent. 'L' : Late. 'P' : Present. A student could be rewarded if his attendance record doesn't contain more than o…
Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around the abandoned Eikou Cram School building, Oshino's makeshift residence. The space is represented by a rectangular grid of n × m cells, arranged into n…
Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows. A positive integer n is decided first. Both Koyomi a…
代码: main: #import <Foundation/Foundation.h> #import "Student.h" int main(int argc, const char * argv[]) { @autoreleasepool { Student *stu1=[[Student alloc]initWithName:]; Student *stu2=[[Student alloc]initWithName:]; Student *stu3=[[Studen…
题目链接: 题目 Problem 1014 xxx游戏 Time Limit: 1000 mSec Memory Limit : 32768 KB 问题描述 小M最近很喜欢玩XXX游戏.这个游戏很简单,仅由3个场景(分别为1.2.3)构成构成,只存在1->2.2->3.3->1的路径,三条路径的时间花费都是1个小时. 由于剧情需要,这个游戏有N个剧情任务,每个剧情任务在其中一个场景中完成,但是某些剧情的触发前提是一些必要剧情任务已经完成.为了简化问题,每个剧情任务都只需要一个小时就可以完…
Problem C. Painting CottagesTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/attachments Description The new cottage settlement is organized near the capital of Flatland. The construction company that is building the sett…
(http://leetcode.com/2011/01/studious-student-problem-analysis.html) You've been given a list of words to study and memorize. Being a diligent student of language and the arts, you've decided to not study them at all and instead make up pointless gam…
Given a positive integer n, return the number of all possible attendance records with length n, which will be regarded as rewardable. The answer may be very large, return it after mod 109 + 7. A student attendance record is a string that only contain…
Problem F. Turning Grille 题目连接: http://opentrains.snarknews.info/~ejudge/team.cgi?SID=c75360ed7f2c7022&all_runs=1&action=140 Description 'Turning grille' method is one of the simplest forms of transposition cipher. A variant of this method is as f…
Problem C. Cargo Transportation 题目连接: http://opentrains.snarknews.info/~ejudge/team.cgi?SID=c75360ed7f2c7022&all_runs=1&action=140 Description The shipping company offers two types of vehicles for bulk cargo transportation. A truck of the first ty…
给定一个正整数 n,返回长度为 n 的所有可被视为可奖励的出勤记录的数量. 答案可能非常大,你只需返回结果mod 109 + 7的值.学生出勤记录是只包含以下三个字符的字符串:    1.'A' : Absent,缺勤    2.'L' : Late,迟到    3.'P' : Present,到场如果记录不包含多于一个'A'(缺勤)或超过两个连续的'L'(迟到),则该记录被视为可奖励的.示例:输入: n = 2输出: 8 解释:有8个长度为2的记录将被视为可奖励:"PP" , &qu…
给定一个字符串来代表一个学生的出勤纪录,这个纪录仅包含以下三个字符:    'A' : Absent,缺勤    'L' : Late,迟到    'P' : Present,到场如果一个学生的出勤纪录中不超过一个'A'(缺勤)并且不超过两个连续的'L'(迟到),那么这个学生会被奖赏.你需要根据这个学生的出勤纪录判断他是否会被奖赏.示例 1:输入: "PPALLP"输出: True 示例 2:输入: "PPALLL"输出: False详见:https://leetc…
分析:a^b+2(a&b)=a+b  so->a^(-b)+2(a&(-b))=a-b 然后树状数组分类讨论即可 链接:http://www.ifrog.cc/acm/problem/1023 吐槽:这个题本来是mod(2^40),明显要用快速乘啊,但是用了以后狂T,不用反而过了,不懂出题人 #include <iostream> #include <algorithm> #include <cmath> #include <vector&g…
You are given a string representing an attendance record for a student. The record only contains the following three characters: 'A' : Absent. 'L' : Late. 'P' : Present. A student could be rewarded if his attendance record doesn't contain more than o…
Given a positive integer n, return the number of all possible attendance records with length n, which will be regarded as rewardable. The answer may be very large, return it after mod 109 + 7. A student attendance record is a string that only contain…
给定一个字符串来代表一个学生的出勤纪录,这个纪录仅包含以下三个字符: 'A' : Absent,缺勤 'L' : Late,迟到 'P' : Present,到场 如果一个学生的出勤纪录中不超过一个'A'(缺勤)并且不超过两个连续的'L'(迟到),那么这个学生会被奖赏. 你需要根据这个学生的出勤纪录判断他是否会被奖赏. 示例 1: 输入: "PPALLP" 输出: True 示例 2: 输入: "PPALLL" 输出: False class Solution {…
USACO ORZ Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3809    Accepted Submission(s): 1264 Problem Description Like everyone, cows enjoy variety. Their current fancy is new shapes for pastu…
传送门:http://codeforces.com/contest/978/problem/D 题意:求变为等差数列,最小要改动的数字个数: 思路:暴力,这道题只用枚举前面两个数字的情况就ok,反思自己在看到这道题的时候各种找规律. 复杂的是3*3*n,我看到群里说的复杂度,内心才恍然大悟. #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #inclu…
题目描述 小易总是感觉饥饿,所以作为章鱼的小易经常出去寻找贝壳吃.最开始小易在一个初始位置x_0.对于小易所处的当前位置x,他只能通过神秘的力量移动到 4 * x + 3或者8 * x + 7.因为使用神秘力量要耗费太多体力,所以它只能使用神秘力量最多100,000次.贝壳总生长在能被1,000,000,007整除的位置(比如:位置0,位置1,000,000,007,位置2,000,000,014等).小易需要你帮忙计算最少需要使用多少次神秘力量就能吃到贝壳. 输入描述: 输入一个初始位置x_0…
任意门:http://poj.org/problem?id=1681 Painter's Problem Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7667   Accepted: 3624 Description There is a square wall which is made of n*n small square bricks. Some bricks are white while some bric…
http://acm.hdu.edu.cn/showproblem.php?pid=6492 题意 他们一共有 n+m+2k 个人,包括 n+k 个男生,m+k 个女生,其中 k 对男女生为异性情侣,现在他们要找房间住.房间有三种类型,双人间 a 元一间,三人间 b 元一间,这两种只能同性一起住.情侣间能住一对异性情侣,一间 c 元.除了情侣间以外,其他房间都可以不住满. 求最少花多少钱,能让小伙伴们都有地方住.(\(n,m,k \leq 10^3\)) 题解 把人分成三部分,男同性,女同性,情…
传送门 题意: 给你 n 个数 a[ 1 ]  ~ a[ n ], n <= 100: 让你找一个 x , 使得 a[ 1 ] = a[ 1 ] ^ x ~ a[ n ] = a[ n ] ^ x: 且 a[ 1 ] ~ a[ n ] 的二进制位上的 1 的个数相等.  每个 a[ i ] <= 2^30: 解: a[ i ] <= 2 ^ 30: 那么x也不会超过 2^30: 那我们暴力枚举两个 2 ^ 15;   分别枚举 x 异或上 a[ i ] 的 低 15, 和 x 异或上 a…
题目链接:http://codeforces.com/contest/812/problem/B 题意 : 给出一个 n (1 ≤ n ≤ 15)层的教学楼, 每一层楼包含 m (1 ≤ m ≤ 100)个房间, 另外每一层的两边还有楼梯口, 接下来有n 行每行有 m+2(包含楼梯口) 用0和1来表示这栋楼的信息, 0代表这个房间的灯没亮, 1代表亮, 现在保安在整栋楼的左下角的楼梯口, 他的目的是关掉这栋楼所有的灯, 而且保安在上楼时他所在的当前楼层灯需全灭才能继续上楼, 而且每经过一个房间和…
题意: 给你一个数x,把这个分解成素数之积(假设是x1*x2*x3),如果   x的每一数位的和   等于  x1每一数位的和加上x2每一数位的和加上x3每一数位的和,那么他就是题目要找的数 示例: 4937775 = 3 * 5 * 5 * 65837 电话号码的所有数字的和为4+9+3+7+7+7+5= 42,其质因数的数字的和为3+5+5+6+5+ 5+8+3+7=42. 题解: 暴力,具体见代码 代码: 1 #include<stdio.h> 2 #include<string.…
题意1: 给你一个由小写字母构成的字符串s,你可以其中某些字符变成大写字母.如果s中有字母a,你如果想把a变成大写,那s字符串中的每一个a都要变成A 最后你需要要出来所有的字符对,s[i]和s[i-1]需要是辅音字母,且s[i]和s[i-1]中需要一个字母大写另一个小写.a.e.i.o.u.w.y这七个字母是元音 输出最大字符对数量 题解1: 首先预处理一下s字符串中字符相邻的数量,就是记录w[s[i-1]][s[i]]的数量 之后二进制枚举所有字母变成大写的情况. 然后枚举这个字母变成大写之后…
题意:给你一个只含\(+\)和\(-\)的字符串,统计它的加减和,然后再给你一个包含\(+,-,?\)的字符串,其中\(?\)可以表示为\(+\)或\(-\),问有多少种情况使得第二个字符串的加减和等于第一个. 题解:首先我们统计第一个字符串的和,然后统计第二个字符串的加减和以及\(?\)的个数,然后对于\(?\)我们进行二进制枚举,枚举它的所有可能情况的和,再加上第二个字符串的和每次判断一下是否和第一个相等即可. 代码: char s[N],t[N]; int main() { //ios::…