题解:CF1015D Walking Between Houses】的更多相关文章

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…
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…
题意:从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&…
Description Natasha is planning an expedition to Mars for nn people. One of the important tasks is to provide food for each participant. The warehouse has mm daily food packages. Each package has some food type ai. Each participant must eat exactly o…
题意:一共有\(n\)个房子,你需要访问\(k\)次,每次访问的距离是\(|x-y|\),每次都不能停留,问是否能使访问的总距离为\(s\),若能,输出\(YES\)和每次访问的房屋,反正输出\(NO\). 题解:最优解一定是让每次访问的距离为\(s/k\),然后将余数\(s\ mod\ k\)平均分配到前s%k的房屋中,之后每次访问\(s/k\)即可,也就是构造一个类似于\(x\ 1\ x\ 1\ x\ 1\)这样的一个序列,但因为有余数,所以要修改. 代码: #include <iostre…
题目链接 题意:给你三个数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的时候,有个远古题没补..好像是去年暑假的题了..今天翻出来补了一下,发现现在的思路明显比当时清晰,好像真的进步了一点…
题意: 现在有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呢?我们可以贪心下,尽可能…
感觉自己有点强迫症  不都写出来就找理由不写题解 http://codeforces.com/contest/1015   题目链接 A. Points in Segments 题目意思  n个线段 去覆盖1-m 中的点 问你没有覆盖的点的个数和位置 这个数据很小,可以直接暴力查找 思考:如果n<1e6, m<=1e8 呢? #include<bits/stdc++.h> #define int long long #define MAX(a,b,c) max(a,max(b,c)…
A - Points in Segments 题意:implement #include<bits/stdc++.h> using namespace std; typedef long long ll; bool vis[105]; int ans[105], atop; void test_case() { int n, m; scanf("%d%d", &n, &m); while(n--) { int u, v; scanf("%d%d&q…
题目描述 Walking RaceTime Limit: 10000MS Memory Limit: 131072KTotal Submissions: 4941 Accepted: 1252Case Time Limit: 3000MS Description flymouse's sister wc is very capable at sports and her favorite event is walking race. Chasing after the championship…