HDU 1273 ORZ

漫步森林

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1607    Accepted Submission(s): 1090

Problem Description

Gardon和小希每天晚上都喜欢到屋外的森林里散步,设森林里有N块空地,任意两块空地之间都有一条小径相通。他们每次从任意一块空地出发,经过所有的空地后回到原来的空地。 
由于他们都喜欢新鲜的旅行,所以他们不希望对任何一条小径经过两次。那么请问,他们最多能保证多少次这种新鲜的旅行呢? 
例如(图),当N=5时,他们只能保持两次这样新鲜的旅行。 

Input

输入包含多组数据,每组数据占一行,是一个数字 N。(0<N<=1000000000) 
文件以一个0结束。

Output

对于每个输入的N,输出最多能保证新鲜旅行的次数。

Sample Input

5

0

Sample Output

2

初看这道题感觉很难的样子,一定牵扯到某些算法,想了半天也没想出能解决这道题的算法。。。于是就把这道题放那了。。= =

吃饭时灵光一现,对于起始点来说,设其周围的边数目为n,每次走往返消耗掉2个边,那么总共能走n/2次,也就是n/2次新鲜旅行。。。想起这个思路我瞬间有点石化的感觉。。。ORZ

代码:

 1 #include <stdio.h>
 2 #include <algorithm>
 3 #include <string.h>
 4 #include <iostream>
 5 #include <vector>
 6 #include <map>
 7 #include <queue>
 8 #include <set>
 9 #include <vector>
10 #include <string>
11 #include <sstream>
12 using namespace std;
13
14 main()
15 {
16     int n;
17     while(scanf("%d",&n)==1&&n)
18     {
19         printf("%d\n",(n-1)>>1);
20     }
21 }

HDU 1273 ORZ

时间: 2024-11-05 14:38:57

HDU 1273 ORZ的相关文章

Xor Sum HDU - 4825(01字典树)

Xor Sum HDU - 4825 (orz从之前从来没见过这种题 1 #include <bits/stdc++.h> 2 using namespace std; 3 #define LL long long 4 const int maxnode = 100010 * 32; 5 const int sigma = 2; 6 struct AC01{ 7 int ch[maxnode][sigma]; 8 LL val[maxnode]; 9 int sz; 10 void init(

hdu 1532 poj 1273 Drainage Ditches (最大流)

Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 55276   Accepted: 21122 Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This means that the clover is covered by

HDU 4277 USACO ORZ(暴力+双向枚举)

USACO ORZ Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3809    Accepted Submission(s): 1264 Problem Description Like everyone, cows enjoy variety. Their current fancy is new shapes for pastu

hdu 4277 USACO ORZ DFS

USACO ORZ Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3581    Accepted Submission(s): 1196 Problem Description Like everyone, cows enjoy variety. Their current fancy is new shapes for pastur

hdu 4277 USACO ORZ(dfs+剪枝)

Problem Description Like everyone, cows enjoy variety. Their current fancy is new shapes for pastures. The old rectangular shapes are out of favor; new geometries are the favorite.I. M. Hei, the lead cow pasture architect, is in charge of creating a

HDU ACM 1273 漫步森林

n个顶点,有(n-1)*n/2条边,每走一次都需要(也只需)n条边才能经过n个顶点,所以最终答案就是(n-1)/2.([(n-1)*n/2]/n). #include<iostream> using namespace std; int main() { int n; while(cin>>n &&n) { cout<<(n-1)/2<<endl; } return 0; }

Drainage Ditches (poj 1273 &amp;&amp; hdu 1532 网络流之Ford-Fulkerson)

Language: Default Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 59676   Accepted: 22909 Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This means that the clo

NYOJ 323 &amp;&amp; HDU 1532 &amp;&amp; POJ 1273 Drainage Ditches (网络流之最大流入门)

链接:click here 题意:给出n个河流,m个点,以及每个河流的流量,求从1到m点的最大流量. 思路:最裸的网络流题目  意思就是求从源点到汇点的最大流. 第一道网络流,一边看着书上的介绍,一边敲下代码: 用的是网络流算法ford-fulkerson 题目数据量小,邻接表和邻接矩阵都可以过 代码: #include <ctype.h> //最大流 入门 #include <stdio.h> #include <vector> #include <stdlib

poj 1273 ---&amp;&amp;--- hdu 1532 最大流模板

最近在换代码布局,因为发现代码布局也可以引起一个人的兴趣这个方法是算法Edmonds-Karp 最短增广路算法,不知道的话可以百度一下,基于Ford-Fulkerson算法的基础上延伸的 其实我不是很透彻的领悟这个算法的精髓,只知道怎样实现,现在的任务就是多刷几道题,见识见识题型,就可以更透彻领悟为什么这么做,之后再拐回来研究算法,这样就可以学习和实践相结合! 详解 : 就是每次广搜后都让走过的边减去这条通路的最小的通路,逆向通路加上这条通路的最小通路,也就是最大容纳量,形成新的通路之后就记录最