zoukankan      html  css  js  c++  java
  • CodeForces1358 C. Celex Update

    题意:给定一张表,求从一个起点(x1, y1)出发到(x2, y2)的所有路径的和的不同数量。

    分析:数学思维题。

    我们先看看每条路径和的关系1--->2--->4--->8--->13,当我们走第二条路径的时候,1--->2--->5--->8--->13的时候,
    路径和增加了1,即5比4多了1,我们依次改良,可以发现每次改变路径的时候,总和会增加1,路径的条数为左下(n - 1) * (m - 1)的方格数目再加上起始挑选的路径数目1,所以答案为(x2 - x1) * (y2- y1) + 1。

    一般c题是道思维题,如果想不到什么好的方法,我们可以尝试样例,找一个小的数据,再对每一条路径进行计算和,查看条数。

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    
    using namespace std;
    
    int main()
    {
    	int t;
    	scanf("%d", &t);
    
    	while (t--)
    	{
    		int x1, y1, x2, y2;
    		scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    
    		printf("%lld
    ", (long long)(y2 - y1) * (x2 - x1) + 1);
    	}
    	return 0;
    }
    
  • 相关阅读:
    信息搜集与漏洞扫描
    ASN.1分析Alipay证书
    任务计划
    2020系统综合实践 期末大作业 21组
    2020系统综合实践 第6次实践作业 2组
    第5次实践作业
    第4次实践作业
    第3次实践作业
    第2次实践作业
    第1次实践作业
  • 原文地址:https://www.cnblogs.com/pixel-Teee/p/12987112.html
Copyright © 2011-2022 走看看