CF D. Walking Between Houses (贪心)】的更多相关文章

题意: 现在有n个房子排成一列,编号为1~n,起初你在第1个房子里,现在你要进行k次移动,每次移动一都可以从一个房子i移动到另外一个其他的房子j里(i != j),移动的距离为|j - i|.问你进过k次移动后,移动的总和可以刚好是s吗?若可以则输出YES并依次输出每次到达的房子的编号,否则输出NO. 分析:首先观察下NO的情况,如果s<k 也就是说总步数都比不是次数的话,那肯定是NO拉,或者s>k*(n-1) 无论如何走都到吧了总步数,那也是NO; 什么时候是YES呢?我们可以贪心下,尽可能…
Walking Between Houses There are nn houses in a row. They are numbered from 11 to nn in order from left to right. Initially you are in the house 11. You have to perform kk moves to other house. In one move you go from your current house to some other…
D. Walking Between Houses time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are nn houses in a row. They are numbered from 11 to nn in order from left to right. Initially you are in th…
题意:从1开始走,最多走到n,走k步,总长度为n,不能停留在原地,不能走出1-n,问是否有一组方案,若有则输出 n<=1e9,k<=2e5,s<=1e18 思路:无解的情况分为两种:总长度太大,步数太多 每次贪心从1走到n或从n走到1,但要注意给剩下的步数留出空间 #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<iostream&…
1.CF #374 (Div. 2)   D. Maxim and Array 2.总结:按绝对值最小贪心下去即可 3.题意:对n个数进行+x或-x的k次操作,要使操作之后的n个数乘积最小. (1)优先队列 #include<bits/stdc++.h> #define F(i,a,b) for (int i=a;i<b;i++) #define FF(i,a,b) for (int i=a;i<=b;i++) #define mes(a,b) memset(a,b,sizeof(…
题目链接: [传送门][1] Pasha Maximizes time limit per test:1 second     memory limit per test:256 megabytes Description Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortu…
题目链接:http://codeforces.com/contest/508/problem/C 题目大意:给你三个数,m,t,r,代表晚上有m个幽灵,我有无限支蜡烛,每支蜡烛能够亮t秒,房间需要r支蜡烛才能被点亮. 接下来有m个数,w[0..m-1],每个幽灵会在w[i]秒来光顾,在w[i]+1秒结束光顾.当房间被点亮的时候,幽灵就不会来了,现在问你,最少需要多少支蜡烛,使得一晚上都没有幽灵来光顾.若不能达到,则输出-1. 蜡烛可能在傍晚来临之前或者傍晚来临之后点亮,每秒只能点亮一支蜡烛,点亮…
其实就是求总长度 - 一个最长“连续”自序列的长度 最长“连续”自序列即一个最长的lis,并且这个lis的值刚好是连续的,比如4,5,6... 遍历一遍,贪心就是了 遍历到第i个时,此时值为a[i],如果a[i]-1在前面已经出现过了,则len[a[i]] = len[a[i-1]]+1 否则len[a[i]] = 1 #include <cstdio> #include <algorithm> #include <cstring> #include <iostr…
题目链接 题意:给你三个数n,k,sn,k,sn,k,s,让你构造一个长度为k的数列,使得相邻两项差值的绝对值之和为sss, ∑i=1n∣a[i]−a[i−1]∣,a[0]=1\sum_{i=1}^n|a[i]-a[i-1]|,a[0]=1∑i=1n​∣a[i]−a[i−1]∣,a[0]=1. 思路:遍历每一步,找到当前能走的步数的最大可能,然后走就好了. 写这个博客是因为看cf的时候,有个远古题没补..好像是去年暑假的题了..今天翻出来补了一下,发现现在的思路明显比当时清晰,好像真的进步了一点…
D. Ciel and Duel time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Fox Ciel is playing a card game with her friend Jiro. Jiro has n cards, each one has two attributes: position (Attack or De…