UVA 10714 Ants 蚂蚁 贪心+模拟 水题】的更多相关文章

题意:蚂蚁在木棍上爬,速度1cm/s,给出木棍长度和每只蚂蚁的位置,问蚂蚁全部下木棍的最长时间和最短时间. 模拟一下,发现其实灰常水的贪心... 不能直接求最大和最小的= =.只要求出每只蚂蚁都走长路下木棍时的最大值,和走短路时的就行了. 代码: /* * Author: illuz <iilluzen@gmail.com> * Blog: http://blog.csdn.net/hcbbt * File: uva10714.cpp * Lauguage: C/C++ * Create Da…
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1323 题意 长方形l * w,给出长方形中间那条线上n个圆的圆心c和半径r,选取最少数目的圆覆盖长方形,选不了输出-1 思路 明显,算出圆在边上的坐标,然后尽量从左向右扩展就行 感想: 卡题的原因是反射性以为r和w很小,但其实可以很大,所以用double存r 代码 #include…
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1980 题意 n个数,要求正负相间,绝对值增长,问n个数能组成的这样数列最长多长 思路 明显,分成正负两组,挨个在两组内取最小,直到不能取就行 代码 #include <algorithm> #include <cassert> #include <cma…
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3049    Accepted Submission(s): 2364 Problem Description You are the CEO of Nasty Hacks Inc., a company that creates small pieces of…
Flow Layout Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3091   Accepted: 2148 Description A flow layout manager takes rectangular objects and places them in a rectangular window from left to right. If there isn't enough room in one r…
题目连接:10714 - Ants 题目大意:一根棍子上有n只蚂蚁, 这些蚂蚁开始可以任意朝着一个方向移动一直走,向左或是向右,并且移动速度是相同的,但是一旦蚂蚁碰到迎面走来的另一只蚂蚁,那么这两只蚂蚁都会马上改变移动方向,朝反方向移动.求所有蚂蚁离开木棍的最小和最长时间. 解题思路:其实题目给出的两只蚂蚁碰头的可能是迷惑人的,因为开始所有蚂蚁都朝一个方向移动,速度又相同,根本不可能追上,所以不用考虑只一点,这样的话只要分别计算出向左和向右所要花费的最长时间,大的为最长时间,小的为最小时间(可以…
题目: 给出一串表示矩阵相乘的字符串,问这字符串中的矩阵相乘中所有元素相乘的次数. 思路: 遍历字符串遇到字母将其表示的矩阵压入栈中,遇到‘)’就将栈中的两个矩阵弹出来,然后计算这两个矩阵的元素相乘的次数,累加就可以了. PS:注意弹出的矩阵表示的先后顺序. 代码: #include <bits/stdc++.h> #define inf 0x3f3f3f3f #define MAX 1000000000 #define mod 1000000007 #define FRE() freopen…
最多时间就是每仅仅蚂蚁选择最久的爬行方式 最少时间就是每仅仅蚂蚁选择最快地爬行方式 #include<iostream> #include<map> #include<string> #include<cstring> #include<cstdio> #include<cstdlib> #include<cmath> #include<queue> #include<vector> #includ…
题目链接:http://poj.org/problem?id=2864 题意:参照题目 哈哈哈,这个题discuss有翻译哦.水到我不想交了. #include <cstdio> #include <cstdlib> #include <cstring> ][]; int main(void) { int r, c; int i, j; int flag; || r != ) { memset(arr, , sizeof(arr)); ; i < r; i++)…
Codeforces 1082B Vova and Trophies https://vjudge.net/problem/CodeForces-1082B 题目: Vova has won nn trophies in different competitions. Each trophy is either golden or silver. The trophies are arranged in a row. The beauty of the arrangement is the le…
一场2012天津网络预选赛的题,签到题. 但是还是写了三四十分钟,C++和STL太不熟悉了,总是编译错误不知道怎么解决. 一开始用的Char [] 后来改成了string,STL和string搭配起来才好用啊. #include <algorithm> #include <iostream> #include <cstring> #include <ctype.h> #include <cstdlib> #include <cstdio&g…
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2683 题意 原来有1个,每次可以任选数量成倍增长,问要操作多少次到n 思路 明显,先扩增到最大数位maxDigit,比如10,先扩增到8,然后再选择n - maxDigit扩增即可.因而结果为log2(n) 代码 #include <algorithm> #include…
http://acm.hdu.edu.cn/showproblem.php?pid=4891 给出一个文本,问说有多少种理解方式. 1. $$中间的,(s1+1) * (s2+1) * ...*(sn+1), si表示连续的空格数. 2.{}中间,即 | 的个数+1. 就是模拟 #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <…
Mishka started participating in a programming contest. There are nn problems in the contest. Mishka's problem-solving skill is equal to kk. Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves…
题目链接:http://poj.org/problem?id=2459 题目大意:有C头牛,下面有C行,每头牛放进草地的时间,每天吃一个草,总共有F1个草,想要在第D的时候,草地只剩下F2个草. 解题思路:模拟啊,就像砍树一样的问题,把每天失去的草计算出来,从最后一天往前推. #include <cstdio> #include <cstring> int C,F1,F2,D; ]; int main() { while (scanf("%d%d%d%d",&a…
题目:https://www.luogu.org/problemnew/show/P1079 大水题. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ,M=; int n,m; char a[N],b[N]; int get_int(char ch) { ; ; } int main() { scanf(); n=s…
题意: 模拟模拟~~ 代码: #include<iostream> using namespace std; const int maxn = 1005; int a[maxn], b[maxn], fa[maxn], fb[maxn]; int main (void) { int n;cin>>n; for(int i = 1; i <= n; i++){ cin>>a[i]; if(i==1) fa[i] = a[i]; else fa[i] = fa[i-1…
 1716: 毒 Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 96  Solved: 43 SubmitStatusWeb Board Description 现有n瓶毒药,第1瓶毒药的毒性为1,第i瓶毒药比第i-1瓶毒药的毒性增长了(((i-1)*K)%M),将第i瓶毒药的毒性记做vi. 你可以将任意两瓶毒药混合.若将第i瓶毒药和第j瓶毒药混合,则混合后的毒药的毒性为2*sqrt(vi*vj).(sqrt表示开方). 合并到最后,将会只剩…
题目链接 一堆小木棍,每个有两个属性值(l,w),对小木棍分组,每一组内的小木棍存在这样一个序列满足s1<=s2<=s3.....<=sn,[s1<=s2当且仅当s1.l<=s2.l&&s1.w<=s2.w],问最小的分组数 ------------------------------------------------------------------------------------------ 贪心 #include <set> #…
https://vjudge.net/problem/UVA-506 题目是给出了五种指令,DEPEND.INSTALL.REMOVE.LIST.END,操作的格式及功能如下: DEPEND item1 item2 (item3 ...) 安装item1需要先安装item2(.item3--) INSTALL item1 安装item1,如果item1依赖其他组件,则先安装其依赖的其他组件 REMOVE item1 移除item1及其依赖的全部组件,如果组件被其他程序依赖,则不移除 LIST 输…
Elevator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 56481    Accepted Submission(s): 30942 Problem Description The highest building in our city has only one elevator. A request list is made…
题目给出图,要求判断不能一遍走完所有边,也就是无向图,题目分类是分欧拉回路,但其实只要判断度数就行了. 一开始以为只要判断度数就可以了,交了一发WA了.听别人说要先判断是否是联通图,于是用并查集并一起,然后判断是否有多个根. 用dfs的话就是深搜时标记下,最后看看有没有全部标记.我没用dfs做. 代码: #include <cstdio> const int maxn = 201; int f[maxn]; int d[maxn]; int find(int x) { if (x != f[x…
Mike and Cellphone 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/E Description While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old…
染色问题,其实就是看看图上某一点能扩散多少. 用DFS解决,因为BFS不是很熟 =-=...以后要多练. 提交后32ms,优化了一下,在递归前进行判定,优化到22ms,不是优化的很好... 代码: #include <cstdio> #include <cstdlib> #include <cstring> char maze[31][81]; void dfs(int x, int y) { maze[x][y] = '#'; if (maze[x - 1][y] =…
题目大意: ·给你一个n,表示输入n个白点和n个黑点(输入每一个点的坐标).现在需要将各个白点和各个黑点一一用线段连接起来,需要满足这些线段不能够相交. ·特色: 我们如何保证线段间不相交. ·分析: 由"黑白"可以想到用二分图匹配(最大流问题亦可).用到一个神秘结论,可以巧妙地将"相交"和"不相交"转化为具体数值大小关系,进而转化为权值.结论为:[四边形两条对角线的和必定大于它任何一组对边的和] 用一下这幅图进行分析:           下面…
n个人 小明编号为m 从编号为a的人开始数 起始数字为b 遇到素数duang 并反相 求小明应该说什么 Sample Input 310 2 //n m3 4 //a b3 32 64 13 8 Sample Output duangduang10 # include <cstdio> # include <cstring> # define LL long long using namespace std ; ; bool notprime[MAXN];//值为false表示素数…
http://acm.hdu.edu.cn/showproblem.php?pid=5083 机器码和操作互相转化 注意SET还要判断末5位不为0输出Error #pragma comment(linker, "/STACK:36777216") #pragma GCC optimize ("O2") #include <cstdio> #include <cstdlib> #include <cmath> #include &l…
你的一系列得分 先降序排列 再按0.95^(i-1)*ai 这个公式计算你的每一个得分 最后求和 Sample Input12530 478Sample Output984.1000000000 # include <iostream> # include <cstdio> # include <algorithm> # include <map> # include <cmath> # define LL long long using nam…
题意:有n个条龙,在雇佣勇士去杀,每个勇士能力值为x,只能杀死头的直径y小于或等于自己能力值的龙,只能被雇佣一次,并且你要给x赏金,求最少的赏金. 析:很简单么,很明显,能力值高的杀直径大的,低的杀直径小的.所以我们先对勇士能力值从小到大排序,然后对龙的直径从小到大排序, 然后扫一遍即可,如某个勇士杀不龙,就可以跳过,扫到最后,如果杀完了就结束,输出费用,否则就是杀不完. 代码如下: #include <iostream> #include <cstdio> #include &l…
题意:给定两个字符串,问第一个串能不能从第二个串通过删除0个或多个字符得到. 析:那就一个字符一个字符的匹配,如果匹配上了就往后走,判断最后是不是等于长度即可. 代码如下: #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #include <cmath> using namespace std; string s1, s2; int mai…