2014北京網路賽1006||hdu5037 思維題
http://acm.hdu.edu.cn/showproblem.php?pid=5037
Problem Description
Once upon a time, there is a little frog called Matt. One day, he came to a river.
The river could be considered as an axis.Matt is standing on the left bank now (at position 0). He wants to cross the river, reach the right bank (at position M). But Matt could only jump for at most L units, for example from 0 to L.
As the God of Nature, you must save this poor frog.There are N rocks lying in the river initially. The size of the rock is negligible. So it can be indicated by a point in the axis. Matt can jump to or from a rock as well as the bank.
You don't want to make the things that easy. So you will put some new rocks into the river such that Matt could jump over the river in maximal steps.And you don't care the number of rocks you add since you are the God.
Note that Matt is so clever that he always choose the optimal way after you put down all the rocks.
The river could be considered as an axis.Matt is standing on the left bank now (at position 0). He wants to cross the river, reach the right bank (at position M). But Matt could only jump for at most L units, for example from 0 to L.
As the God of Nature, you must save this poor frog.There are N rocks lying in the river initially. The size of the rock is negligible. So it can be indicated by a point in the axis. Matt can jump to or from a rock as well as the bank.
You don't want to make the things that easy. So you will put some new rocks into the river such that Matt could jump over the river in maximal steps.And you don't care the number of rocks you add since you are the God.
Note that Matt is so clever that he always choose the optimal way after you put down all the rocks.
Input
The first line contains only one integer T, which indicates the number of test cases.
For each test case, the first line contains N, M, L (0<=N<=2*10^5,1<=M<=10^9, 1<=L<=10^9).
And in the following N lines, each line contains one integer within (0, M) indicating the position of rock.
For each test case, the first line contains N, M, L (0<=N<=2*10^5,1<=M<=10^9, 1<=L<=10^9).
And in the following N lines, each line contains one integer within (0, M) indicating the position of rock.
Output
For each test case, just output one line “Case #x: y", where x is the case number (starting from 1) and y is the maximal number of steps Matt should jump.
Sample Input
2
1 10 5
5
2 10 3
3
6
Sample Output
Case #1: 2
Case #2: 4
我參考:http://blog.csdn.net/u014569598/article/details/39471913
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
int n,m,l,a[200005];
int main()
{
int T,tt=0;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&m,&l);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
a[0]=0;a[++n]=m;
sort(a,a+n+1);
int k=l;
int ans=0;
for(int i=1;i<=n;i++)
{
int x=(a[i]-a[i-1])%(l+1);
int y=(a[i]-a[i-1])/(1+l);
if(k+x>l)
{
ans+=2*y+1;
k=x;
}
else
{
ans+=2*y;
k+=x;
}
}
printf("Case #%d: %d\n",++tt,ans);
}
return 0;
}
相關文章
- zcmu——2014: 一生之敵(思維題)
- 威馬汽車閆楓:造車新賽道的網際網路思維
- 藍思維網路營銷交流平臺
- 挑選方案問題(牛客競賽 思維題+推導公式)公式
- ACM-ICPC 2018 南京賽區網路預賽__J. Sum【尤拉篩法+質因子分解+思維】ACM
- 高校網路安全管理運維賽2024運維
- 2024高校網路安全管理運維賽 wp運維
- 2018 徐州網路賽 G 題解
- 2024ccpc網路賽補題
- 如何用寫小說的思維做網路安全?
- 2014中國網路效能報告
- 擺脫IT思維,工業網際網路才能走深向實
- 計網複習筆記【附思維導圖】——【4】網路層筆記
- 2018 北京賽區網路預選賽 A. Saving Tang Monk II(BFS+優先佇列)佇列
- 組合計數思維題
- 好玩的木樁(思維題)
- 思維題專項訓練
- 思維體系---技術思維、業務資料思維、產品思維、複合思維
- 從消費網際網路到產業網際網路:平臺思維始終是主導產業
- 技術思維解決“現金貸”危機——如何讓網際網路金融更加“網際網路”?
- 而“優獲客”的這種營銷理念和思維來源於對“現代網際網路思維”的深度認知
- [北京] 學而思網校招聘PHP實習生PHP
- Find the Maximum - 題解【思維,貪心】
- Android 進階路線(思維導圖)Android
- 淺析工具思維、產品思維、品牌思維與定位
- 網際網路運營者為什麼要會運用熱點思維?
- 2020ICPC 江西省賽 B. Apple(思維)APP
- Leetcode第 217 場周賽(思維量比較大)LeetCode
- 求職思維和招聘思維求職
- 測試筆試邏輯思維題筆試
- CF538B Quasi Binary 思維題
- 怎麼凸顯主題?極思維
- AtCoder Beginner Contest 中的小思維題
- P4715 【深基16.例1】淘汰賽 【思維】
- 高校戰“疫”網路安全分享賽-部分PWN題-wp
- 2024ICPC網路賽第一場題解(部分)
- 告別傳統工業網際網路,提高數字管控思維:三維組態分散式能源站分散式
- 把流量思維變成留量思維
- 北京知名網際網路公司招聘golang工程師Golang工程師