Stones |
Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 4160 Accepted Submission(s): 2695 Problem Description Because of the wrong status of the bicycle, Sempr begin to walk east to west every morning and walk back every evening. Walking may cause a little tired, so Sempr always play some games this time. Input In the first line, there is an Integer T(1<=T<=10), which means the test cases in the input file. Then followed by T test cases. Output Just output one line for one test case, as described in the Description. Sample Input
Sample Output
11 12 题意: 这道题其实挺简单的,只是题目有点儿难读懂(英语渣渣的我瑟瑟发抖) 题目说的大概就是小明在路上会遇见一些石头,对于小明遇到的第i个石头,如果i是奇数,小明会把它扔出去di米 如果i是偶数,小明就继续走;现在让我们结合样例来看,对于样例1,小明首先总共会遇到两个石头,第一次(奇数)遇见距离他1米他能扔5米的石头,于是他把这枚石头扔了5米远,这个石头现在具体小明出发时的位置5 + 1 = 6米,小明继续往前走第二次(偶数)遇到了距离他起点2米的石头,他没有扔并继续往前,又第三次(奇数)遇到了距离他起点为6米他能扔5米的石头(其实就是他第一次遇见的那个),于是他把这枚石头又扔了5米,现在这个石头距离起点11米,小明继续往前走并第四次(偶数)遇见了刚才扔的那个石头,小明没有扔,小明继续往前走,然而小明并不会再遇到石头了,结束,综上,样例1最远的石头距离小明的出发点应该是11米; 样例2也是如此 思路: 这题用优先队列再合适不过了,首先用一个结构体存石头距起点的距离和小明能扔的距离,用优先队列存结构体,距离起点越近优先级越高,如果一次性遇见多个石头,则取扔的近的的那个,对于数据的操作则是用一个变量i记录次序,i为奇则扔并把新的放入队列,i为偶则出队; 代码: #include<cstdio> |
hdu1896 Stones
猜你喜欢
转载自blog.csdn.net/cloudy_happy/article/details/81237244
今日推荐
周排行