题目链接:http://codeforces.com/problemset/problem/752/C time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Santa Claus has Robot which lives on the infinite grid and can move along its lines. He…
题目链接:http://codeforces.com/contest/752/problem/C 题意:给出一系列机器人的行动方向(机器人会走任意一条最短路径),问最少标记几个点能让机器人按这个 路径走下去. 显然最后位置肯定要标记,然后怎么使得点最少呢.首先标记一下起点由于机器人走的是最短路一旦第i个点到 标记点的距离小于第i-1个点到标记点的距离是肯定不能这么走,于是这时就要标记一下上个点的位置,统计数 加1. #include <iostream> #include <cstrin…
C. Santa Claus and Robot time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Santa Claus has Robot which lives on the infinite grid and can move along its lines. He can also, having a sequence…
题意:给定一个机器人的行走路线,求最少的点能使得机器人可以走这样的路线. 析:每次行走,记录一个方向向量,每次只有是相反方向时,才会增加一个点,最后再加上最后一个点即可. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #…
题意:机器人在网格线上行走,从p1点开始,沿最短路径到p2,再沿最短路径到p3,依此类推.在此过程中留下了行走的运动轨迹,由“RLDU”表示.问若只给出运动轨迹,求最少的pi点的个数. 分析:pi到pi+1是沿最短路径走的,因此在此路径中不可能同时出现“UD”两个方向(“LR”同理).因此只要同时出现,那一定证明此刻已往下一个目标点走. #pragma comment(linker, "/STACK:102400000, 102400000") #include<cstdio&g…
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Santa Claus has Robot which lives on the infinite grid and can move along its lines. He can also, having a sequence of m pointsp1, p2, ..., …
E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Santa Claus has n tangerines, and the i-th of them consists of exactly ai slices. Santa Claus came to a school…
题面: 传送门 B. Santa Claus and Keyboard Check Input file: standard input Output file: standard output Time limit: 2 second Memory limit: 256 megabytes   Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he su…
题面传送门 很容易发现一件事情,那就是数组的每一位都是独立的,但由于这题数组长度 \(n\) 很大,我们不能每次修改都枚举每一位更新其对答案的贡献,这样复杂度必炸无疑.但是这题有个显然的突破口,那就是 \(k\) 的取值范围很小,最高只有 \(12\),也就是说每一位的取值最多只有 \(12\) 种可能,我们考虑以此为突破口,设计一个与这 \(k\) 个数的具体取值无关的状态. 首先我们知道每一位是独立的,故我们可以把每一位拆开来考虑,于是问题由二维变成一维:给定 \(k\) 个数 \(a_1,…
http://codeforces.com/contest/752/problem/C 这题的意思其实就是叫你固定x个点,使得按顺序走这x个点后,产生的轨迹是给定的序列. 对于有若干条最短路径走到第i个点,这些情况可以忽略,就是你可以默认走的是任意一条最短路径. 对于一个序列,可以固定两个方向,只要一直都是这两个方向的,就不用设置点了. 比如一直都是RURURURURU,这些情况是不用设置点的,当另一个变量来的时候,比如需要D了,就需要设置一个点了. 有一些需要注意的地方是, 比如 RLL,这样…
http://codeforces.com/contest/738/problem/D https://www.cnblogs.com/flipped/p/6086615.html   原 题意:海战棋游戏,长度为n的01串,1代表炸过且没有船的位置,0代表没有炸过的位置.有a个船,长度都是b,求打到一艘船至少还需要多少炸弹,并输出炸的位置. 分析:每连续的b个0就要炸一次,不然不知道有没有是不是刚好一艘船在这b个位置上面.贪心可知炸这b个的最后一个最划算.因为只要炸到一艘即可,所以答案减去a-…
雅礼集训期间我好像考完试就开始划水了啊 给出k个长度相同的字符串,每个串有一个权值,选出一些串连成一个回文串.使得选中的串的总权值最大. 如果选一个串,必须同时选一个对称的串.还有一个特殊情况是可以在最中间放一个回文的串,求一下这种情况带来的额外的收入即可. 卡自然溢出hash....需要树同构那种奇奇怪怪的hash... #include <cstdio> #include <string> #include <iostream> #include <algor…
题意:将n个蛋糕分给k个人,要保证每个人都有蛋糕或蛋糕块,蛋糕可切, 1.若蛋糕值为偶数,那一次可切成对等的两块. 2.若蛋糕值为奇数,则切成的两块蛋糕其中一个比另一个蛋糕值多1. 3.若蛋糕值为1,则不可切. 问每个人拥有的蛋糕中最小蛋糕值可能的最大值是多少. 分析: 1.若每个蛋糕都分成蛋糕值为1,即n个蛋糕的蛋糕值总和<k,则输出-1. 2.验证mid是否成立,若某蛋糕值x大于mid,则可切,并将该蛋糕可切成的块数保存在vis[x]中. 3.若mid为5,而x为11,则有必要切蛋糕x,若x…
题意:给定k个长度为n的字符串,每个字符串有一个魅力值ai,在k个字符串中选取字符串组成回文串,使得组成的回文串魅力值最大. 分析: 1.若某字符串不是回文串a,但有与之对称的串b,将串a和串b所有的魅力值分别从大到小排序后,若两者之和大于0,则可以放在回文串的两边. 2.若某字符串是回文串,将其魅力值从大到小排序后,两两依次分析:(mid---可能放在回文串中间的串的最大魅力值) (1)若两个数都是正的,那么就将其放在两边,并将结果计入ans.(ans---回文串两边的串的魅力值之和) (2)…
题意:给定两个字符串a和b,问有多少种不同的字母组合对,使得将这些字母对替换字符串b后,可以变成字符串a.注意字母对彼此各不相同. 分析:vis[u]记录与u可形成关系的字母,若u与v不同,则形成字母对.若之后该关系被打破,则输出-1. #pragma comment(linker, "/STACK:102400000, 102400000") #include<cstdio> #include<cstring> #include<cstdlib>…
题目链接:http://codeforces.com/problemset/problem/616/E 题意很简单就不说了. 因为n % x = n - n / x * x 所以答案就等于 n * m - (n/1*1 + n/2*2 ... n/m*m) 在根号n复杂度枚举x,注意一点当m>n时,后面一段加起来就等于0,就不用再枚举了. 中间一段x1 ~ x2 的n/x可能相等,所以相等的一段等差数列求和. //#pragma comment(linker, "/STACK:102400…
A. Anastasia and pebbles time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she…
一个思维水题 题目大意为,一个邮递员要投递N封信,一次从邮局来回只能投递K封.求最短的投递总距离.需注意,最后一次投递后无需返回邮局. 本题思路要点: 1.最后一次投递无需返回邮局,故最后一次投递所行走距离不必乘2(即不必记录返程),所以最后一次投递的是最远的三个信: 2.画图模拟可知,我们可将正负轴的邮件分开进行处理,先处理某一轴的全部信件,在处理另一轴的全部信件: 根据上述思路可得如下代码: #include<iostream> #include<algorithm> #inc…
A - Balloon Robot Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3981 Description The 2017 China Collegiate Programming Contest Qinhuangdao Site is coming! There will be \(n\) teams participating…
题目描述 B君和G君聊天的时候想到了如下的问题. 给定自然数l和r ,选取2个整数x,y满足l <= x <= y <= r ,使得x|y最大. 其中|表示按位或,即C. C++. Java中的|运算. Input 包含至多10001组测试数据. 第一行有一个正整数,表示数据的组数. 接下来每一行表示一组数据,包含两个整数l,r. 保证 0 <= l <= r <= 10181018. Output 对于每组数据输出一行,表示最大的位或. 样例 Sample Input…
题目链接:https://zhixincode.com/contest/18/problem/A?problem_id=259 题目描述 wls正在玩一个寻宝游戏. 宝藏一共有 $n$ 种,都藏在一个 $m$ 行 $m$ 列的网格中. 每种宝藏都恰好有两个. wls只能沿着网格走(上下左右四个方向). 他想依次获得 $1...n$ 类宝藏,然后再以 $n...1$ 的顺序获得剩下的宝藏. wls可以从任意点出发. 当wls到达某个宝藏的位置时,他可以选择取或不取这个宝藏. 请问他最少要移动多少距…
Problem Description HazelFan is given two positive integers a,b, and he wants to calculate amodb. But now he forgets the value of b and only remember the value of a, please tell him the number of different possible results.   Input The first line con…
题目描述 On a plane are nn points ( x_{i}xi​ , y_{i}yi​ ) with integer coordinates between 00 and 10^{6}106 . The distance between the two points with numbers aa and bb is said to be the following value:  (the distance calculated by such formula is calle…
http://arc063.contest.atcoder.jp/tasks/arc063_b 因为每次都是选取最大值,那么用dp[i]表示第i个数结尾能得到最大是多少. 其实就是用a[i]去减去左边最小的那个数字. 然后就是统计有多少个一样的最大值了.. hack点 T是没用的,我被坑了,以为最多只能T / 2次,那么答案是min(T / 2, cnt_max) 但是不是.就算你T / 2只是1,那么,我也可以走不同的道路来取得max,所以要改变的cnt_max还是要改变. 和T无关.. #i…
题目: 题意:输入一个整数n,接着输入2*n个数字,代表2*n个选手的实力.    实力值大的选手可以赢实力值小的选手,实力值相同则都有可能赢.    叫你把这2*n个选手分成2个有n个选手的队伍.    问你是否有一种分法让一个队伍必定会赢. 分析:就像田忌赛马,我们要让第一个队更多的选手赢,全赢输出YES,否则输出NO. 所以我们只需要让第一个队最弱的选手能胜过第二个队最强的选手,我们就可以保证第一个队一定会赢. 代码: #include <bits\stdc++.h> using nam…
1272 最大距离  题目来源: Codility 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题  收藏  关注 给出一个长度为N的整数数组A,对于每一个数组元素,如果他后面存在大于等于该元素的数,则这两个数可以组成一对.每个元素和自己也可以组成一对.例如:{5, 3, 6, 3, 4, 2},可以组成11对,如下(数字为下标): (0,0), (0, 2), (1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (3, 3), (…
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Santa Claus has n tangerines, and the i-th of them consists of exactly ai slices. Santa Claus came to a school which has k pupils. Santa dec…
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Santa Claus likes palindromes very much. There was his birthday recently. k of his friends came to him to congratulate him, and each of them…
D. Santa Claus and a Palindrome time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Santa Claus likes palindromes very much. There was his birthday recently. k of his friends came to him to co…
E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Santa Claus has n tangerines, and the i-th of them consists of exactly ai slices. Santa Claus came to a school…