题目链接:Salem and Sticks 题目原文 Salem gave you …
POJ 3069 Saruman's Army(萨鲁曼军) Time Limit: 1000MS   Memory Limit: 65536K [Description] [题目描述] Saruman the White must lead his army along a straight path from Isengard to Helm’s Deep. To keep track of his forces, Saruman distributes seeing stones, know…
萨鲁曼的军队(Saruman's Army) 代码(C) 本文地址: http://blog.csdn.net/caroline_wendy 题目: 直线上有N个点, 每个点, 其距离为R以内的区域里, 必须带有标记的点, 本身的距离为0. 尽可能少的加入�标记点, 至少要有多少点被加上标记? 贪心算法, 从最左边的点開始, 依次查找距离为R须要加入�标记的点, 直到结束. 代码: /* * main.cpp * * Created on: 2014.7.17 * Author: spike *…
A. Salem and Sticks time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Salem gave you nn sticks with integer positive lengths a1,a2,…,ana1,a2,…,an. For every stick, you can change its length t…
CodeForce 855B 暴力or线段树 题意 给你一串数,然后找出三个数,他们的前后关系和原来一样,可以相同,然后分别乘p,q,r,求他们积的和最大,并且输出这个数. 解题思路 这个可以使用线段树来做,找出区间内的最小值和最大值,如果x(代表pqr中的一个)小于零,就乘以这个区间的最小值,如果大于零,就乘以这个区间的最大值.然后\(j\)从1到n开始遍历. 或者可以暴力,不过这个暴力比一点重方法还要好,我看完就惊呆了,lxm大佬太强了. 代码实现 第一种: #include<cstdio>…
链接:https://codeforces.com/contest/1105/problem/A 题意: 给n个数,找到一个数t使i(1-n)∑|ai-t| 最小. ai-t 差距1 以内都满足 思路: 暴力,枚举. 代码: #include <bits/stdc++.h> using namespace std; typedef long long LL; const int MAXN = 1000+5; int a[MAXN]; int main() { int n; scanf(&quo…
#include <bits/stdc++.h> using namespace std; int main() { int n;cin>>n; int a[n];for(int &i:a) cin>>i; int ans_ave=0,ans_cost=INT_MAX; for(int i=1;i<=100;i++){ int ave=i,cost=0; for(int j:a){ if(j<i) cost+=i-1-j; else if(j>…
A. Salem and Sticks time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Salem gave you nn sticks with integer positive lengths a1,a2,…,ana1,a2,…,an. For every stick, you can change its length t…
  牛的大扫除 题目大意:农夫有N只牛,这些牛要帮助打扫农舍,这些牛只能打扫固定位置(千万要注意这个位置不是连续的),每一段区间必须至少有一只牛打扫,问你至少需要多少只牛?(如果区间不能完全被覆盖,则输出-1). 这一题有点像上次的萨鲁曼军队,就是一个区间贪婪算法,我们尽可能的由一个方向往前找到最大的区间就可以了(如果与本位置的endT的间隔相同,找最远的,贪婪的最基本的思想). 这一题本身不难,但是特判很恶心,一不小心就要出错了,比如1 5 3 1这样的输入,就直接输出-1就可以了(一定要有牛…
2015-09-06 萨鲁曼军队 问题大意:萨鲁曼白想要让他的军队从sengard到Helm’s Deep,为了跟踪他的军队,他在军队中放置了魔法石(军队是一条线),魔法石可以看到前后距离为R的距离,为了让魔法石发挥最大的效益,魔法石戴在军人的身上,问你怎么才能使用最少的石头 问题很清晰,思路也很清晰,这道题挺典型的,就是贪心算法, 很容易想到的就是我们只用在距离内找到最后的点(人),然后把魔法石放到其上面就行了,然后依次类推,最后就可以达到最少的数量 具体可以以2R为一次循环,在前R的区间内我…
A. Salem and Sticks 签. #include <bits/stdc++.h> using namespace std; #define N 1010 int n, a[N]; int work(int x) { ; ; i <= n; ++i) res += max(, abs(x - a[i]) - ); return res; } int main() { while (scanf("%d", &n) != EOF) { ; i <…
[SinGuLaRiTy-1024] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. [POJ 2709] 颜料 (Painter) 题目描述 杂货店出售一种由N(3<=N<=12)种不同颜色的颜料,每种一瓶(50ML),组成的颜料套装.你现在需要使用这N种颜料:不但如此,你还需要一定数量的灰色颜料.杂货店从来不出售灰色颜料——也就是它不属于这N种之一.幸运的是,灰色颜料是比较好配置的,如果你取出三种不同颜色的颜料各x ml,混合起来就…
A. Salem and Sticks 题目描述 Salem gave you n n n sticks with integer positive lengths a1,a2,…,an a_1, a_2, \ldots, a_n a1​,a2​,…,an​ . For every stick, you can change its length to any other positive integer length (that is, either shrink or stretch it)…
T1 光哥为了不让某初二奆佬恶心到我们而留下的火种 (貌似没这题平均分就100-了) 思路:就一横一竖让后就gztopa嘛 #include <bits/stdc++.h> using namespace std; int bigg,n; int l,r; ]; ]; int main(){ scanf("%d",&n); ;i<=;i++) puke[i]=; puke[]+=; ;i<=n;i++){ scanf("%d",&am…
A. Sasha and Sticks time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and…
[题意描述] George用相同的长度棍子,将他们随机切成最多64个单位的长度,现在,他想回到原来的状态,但他忘了他原来的多少根,以及他们原本是多长.请帮助他和设计一个程序,计算最小的可能的原始长度.所有长度均大于零的整数. [输入] 输入包含2行的块.第一行:切成多少根,最多有64根.第二行切成的每一根的长度.文件的最后一行包含零,表示结束. [输出] 输出每行应包含原始棒的最小可能长度. [输入样例] 9 5 2 1 5 2 1 5 2 1 4 1 2 3 4 0 [输出样例] 6 5 附源…
嘤嘤嘤,实习半年多的小蒟蒻的第一篇博客(题解) 英文的: There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a woodworking machine in one by one fashion. It needs some time, called setup time, for the m…
来源:点击打开链接 非常easy.找规律. 每去掉一个点,点的总数量就减去n+m-1,然后看谁最先减到没有点可减.就能够了. #include <iostream> #include <cstring> using namespace std; int main() { int n,m; cin>>n>>m; int totalpoint=n*m; int count=0; while(totalpoint>0) { totalpoint-=(n+m-…
Sticks Problem's Link:   http://poj.org/problem?id=1011 Mean: http://poj.org/problem?id=1011&lang=zh-CN&change=true analyse: 爆搜,但是其中蕴含着很多剪枝. Time complexity: O(n^2) Source code:  // Memory Time // 1347K 0MS // by : Snarl_jsb // 2014-11-07-17.14 #i…
题目链接 题意 : 把每根棍往地上扔,找出最后在上面的棍,也就是说找出所有的没有别的棍子压在它的上面的棍子. 思路 : 对于每根棍子,压在他上面的棍子一定是在它之后扔的棍子,所以在找的时候只要找它之后的线段是否与他相交即可. #include <stdio.h> #include <iostream> #include <math.h> #include <string.h> using namespace std ; struct point { doub…
题目链接 题意: 地上有n种棍子, 其中有两种类型, 一种类型是可识别, 一种类型是不可识别, 每个棍子都有一个权值. 当你捡到可识别的, 那么你以后就不会再捡这个棍子, 如果是不可识别的, 那么你有可能还会捡. 问将所有棍子收集完的权值的期望. 思路: 此题借鉴参考了此篇文章:Aladdin and the Magical Sticks 首先, 这个题初看起来, 和LightOj 1027  A Dangerous Maze有点像, 只不过, 这里是要将所有的门都走遍. 先引入一个经典的问题:…
Sticks Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 125918   Accepted: 29372 Description George took sticks of the same length and cut them randomly until all parts became at most 50 units long. Now he wants to return sticks to the or…
题解:每放一根棍子,都判断一下它与它前面的且在顶端的棍子是否相交,相交的话则将相应的棍子从解空间中除去. #include <cstdio> const double eps=1e-14; const int maxn=1e5+10; struct node{double x1,y1,x2,y2;int w;}e[maxn],f[maxn]; double cross(double x1,double y1,double x2,double y2){return x1*y2-x2*y1;} i…
木棒 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 118943 Accepted: 27429 Description 乔治拿来一组等长的木棒.将它们随机地砍断.使得每一节木棍的长度都不超过50个长度单位.然后他又想把这些木棍恢复到为裁截前的状态,但忘记了初始时有多少木棒以及木棒的初始长度.请你设计一个程序,帮助乔治计算木棒的可能最小长度.每一节木棍的长度都用大于零的整数表示. Input 输入包括多组数据,每组数据包括两…
题意:给出一段无限长的棍子,切一刀需要的代价是棍子的总长,例如21切一刀 变成什么长度 都是代价21 列如7切成5 和2 也是代价7题解:可以利用霍夫曼编码的思想 短的棍子就放在底层 长的尽量切少一次 直接用优先队列 取前2个和一个然后代价加起来就好 有一个小trick就是 只有一个棍子的时候要特判 还有sum要开Long long #include<vector> #include<cstdio> #include<iostream> #include<queu…
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends. Today he invented one simple game to play with Lena, with whom he shares a desk. The rules…
Codeforces Round #297 (Div. 2)C. Ilya and Sticks Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  Solved: 2xx 题目连接 http://codeforces.com/contest/525/problem/C Description In the evening, after the contest Ilya was bored, and he really felt like ma…
Description Stan has n sticks of various length. He throws them one at a time on the floor in a random way. After finishing throwing, Stan tries to find the top sticks, that is these sticks such that there is no stick on top of them. Stan has noticed…
Salem gave you nn sticks with integer positive lengths a1,a2,-,ana1,a2,-,an. For every stick, you can change its length to any other positive integer length (that is, either shrink or stretch it). The cost of changing the stick's length from aa to bb…
Sticks 时间限制:3000 ms  |  内存限制:65535 KB 难度:5   描述 George took sticks of the same length and cut them randomly until all parts became at most 50 units long. Now he wants to return sticks to the original state, but he forgot how many sticks he had origin…