ZOJ 1037 && HDU 1046 Gridland (找规律)

链接:click here

题意: 给你 一张图,问你从起点出发,最后回到起点的最短路程

思路:

当n,m有一者能够为偶数时,结果是n*m否者必有一条路需要斜着走,结果为n*m-1+1.41

代码:

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<set>
#include<vector>
#include<map>
#include<math.h>
#include<queue>
#include<string>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int a[1000000];
int main()
{
    int ncase,m,i,j=1;
    cin>>ncase;
    while(ncase--)
    {
        double n,m;
        cin>>n>>m;
        printf("Scenario #%d:\n",j++);
        if((int )n%2==0||(int ) m%2==0)
            printf("%.2lf\n",n*m);
        else printf("%.2lf\n",n*m-1+sqrt(2.0));
        printf("\n");
    }
    return 0;
}
时间: 2024-10-16 11:53:41

ZOJ 1037 && HDU 1046 Gridland (找规律)的相关文章

HDU ACM 1046 Gridland 找规律

分析:给出一个矩阵,问最短从一个点经过所有点以此回到起点的长度是多少.画图很好理解,先画3*4.3*3.4*4的点阵图案,试着在上面用最短路走一走,可以发现当矩形点阵的长宽都是奇数时,最短路中必定有一条斜线:而只要长或宽有一个是偶数就可以通过直线来完成最短路经,因此只需判断一下两边的奇偶情况就能求最短路径了. #include<iostream> #include<cmath> using namespace std; int main() { int T,t=0,m,n; cin

zoj 3629 Treasure Hunt IV(找规律)

Alice is exploring the wonderland, suddenly she fell into a hole, when she woke up, she found there are b - a + 1 treasures labled a fromb in front of her.Alice was very excited but unfortunately not all of the treasures are real, some are fake.Now w

hdu 1046 Gridland

Gridland Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5137    Accepted Submission(s): 2342 Problem Description For years, computer scientists have been trying to find efficient solutions to d

HDU 1046.Gridland【非搜索,找规律】【8月25】

Gridland Problem Description For years, computer scientists have been trying to find efficient solutions to different computing problems. For some of them efficient algorithms are already available, these are the "easy" problems like sorting, ev

组队赛#1 解题总结 ZOJ 3798 Abs Problem (找规律+打表)

Abs Problem Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge Alice and Bob is playing a game, and this time the game is all about the absolute value! Alice has N different positive integers, and each number is not greater than N.

ZOJ 3829 Known Notation --贪心+找规律

题意:给出一个字符串,有两种操作: 1.插入一个数字  2.交换两个字符   问最少多少步可以把该字符串变为一个后缀表达式(操作符只有*). 解法:仔细观察,发现如果数字够的话根本不用插入,数字够的最低标准为'*'的个数+1,因为最优是 '12*3*..' 这种形式,所以先判断够不够,不够就补,然后从左往右扫一遍,如果某个时刻Star+1>Num,那么从开始到这一段是不合法的,要把那个'*'与后面的一个数字交换,此时Star--,Num++.然后步数++.这样得出的结果就是最后的最小步数. 脑子

HDU 5084 HeHe --找规律

题意: 给出矩阵M,求M*M矩阵的r行c列的数,每个查询跟前一个查询的结果有关. 解法: 观察该矩阵得知,令ans = M*M,则 ans[x][y] = (n-1-x行的每个值)*(n-1+y列的每个值).直接对每个查询做n次累加(n*m=10^8的复杂度)竟然可以水过. 官方题解给的是n^2的算法,维护一个前缀和,即sum[i][j] 表示 i+j不变的所有sum[i][j]之和. 因为 ans[x][y]就是 a[y]*a[2*n-x] + .... + a[y+n-1]*a[n-x+1]

HDU 1847 (博弈 找规律) Good Luck in CET-4 Everybody!

多写几个就会发现3的倍数是必败点,担心可能有例外,我一直写到第15个.. 1 #include <cstdio> 2 3 int main() 4 { 5 int n; 6 while(scanf("%d", &n) == 1 && n) 7 printf("%s\n", n % 3 ? "Kiki" : "Cici"); 8 9 return 0; 10 } 代码君

hdu 5139 Formula (找规律+离线处理)

Formula Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 206    Accepted Submission(s): 83 Problem Description f(n)=(∏i=1nin−i+1)%1000000007You are expected to write a program to calculate f(n) w