【第22期】观点:IT 行业加班,到底有没有价值?

【cf】Restoring Paintie

原创 2016年05月31日 17:05:08

原题

题意:每个2*2的矩形和都相等,求满足该矩形的方法数。


1.思路:

将其余几个空格从左到右,从上到下为e,f,g,h,i,列出b+e=f+c,b+h=c+i,a+e=h+d,a+f=d+i,即g(正中间的数)可取任何数,所以求出方法数,然后*n。枚举其中一个未知数e,将其他未知数用已知数表示出来,通过for循环求解。

<span style="font-family:SimSun;font-size:18px;"><strong>#include<stdio.h>
int main(){
	int n,a,b,c,d,e,f,g,h,i;
	while (scanf("%d%d%d%d%d",&n,&a,&b,&c,&d)!=EOF){
		long long sum=0;
		for (e=1;e<=n;e++){
			f = e-c+b;
			h = a-d+e;
			i = a-d+f;
			if ((f>=1&&f<=n)&&(h>=1&&h<=n)&&(i>=1&&i<=n))
			sum++;
		}
		printf("%lld\n",sum*n);
	} 
	return 0;
}</strong></span>
2.思路:

由1,正中间的可取任何数, 假设左上角放的是x,根据可以得到三个方程;
         f: 1<=x+b-c<=n,所以 c-b+1<=x<=c-b+n;
         h:1<=x+a-d<=n,所以d-a+1<=x<=d-a+n;
         i:1<=a+b+x-c-d<=n,所以c+d-a-b+1<=x<=c+d-a-b+n;
          同时1<=x<=n;
          所以x最小可以取cnt1=max(1,c-b+1,d-a+1,c+d-a-b+1);
                  最大可以取cnt2=min(n,c-b+n,d-a+n,c+d-a-b+n);
          如果cnt2<cnt1,没有可行解,答案是0; 否则ans=(cnt2-cnt1+1)*n;

#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int n,a,b,c,d,i,cnt1,cnt2;
	long long ans;
    while (scanf("%d%d%d%d%d",&n,&a,&b,&c,&d)!=EOF){
    	cnt1=max(1,max(max(c-b+1,d-a+1),c+d-a-b+1));
    	cnt2=min(n,min(min(c-b+n,d-a+n),c+d-a-b+n));
    	if(cnt2>=cnt1)
    	ans=(long long)(cnt2-cnt1+1)*n;
    	else ans=0;
    	printf("%lld\n",ans);
	}
    
    return 0; 
}
3.思路:

#include <iostream>
using namespace std;
main(){
int n,a,b,c,d;
cin>>n>>a>>b>>c>>d;
cout<<max(n-abs(a-d)-abs(b-c),0)*1ll*n;
}



版权声明:本文为博主原创文章,未经博主允许不得转载。 举报

相关文章推荐

[CF509D] Restoring Numbers && 构造

构造的时候把a0视为0  构造出可能有负数的序列a b 再构造出矩阵e e[i][j] = |a[i] + b[j] - w[i][j]| 若e都为0 则k取大于w中所有数字的值即可 若e[i]...

Restoring Active Directory

There are two ways to restore Active Directory. You can reinstall Windows 2000, and then let normal replication repopulate Active Directory through the normal replication process, or you can restore Active Directory from a backup. The first method restores Active Directory to the current

2017暑期集训一Restoring Painting(思维)

K - *Restoring Painting(思维)  CodeForces - 675B  Vasya works as a watchman in the gallery...

Restoring the Quick Launch toolbar "Show Desktop" icon

Restoring the Quick Launch toolbar "Show Desktop" icon It is fairly easy to restore the "Show De

K - *Restoring Painting(思维)

Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was sto...
  • gtuif
  • gtuif
  • 2017-07-21 18:42
  • 47
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)