【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;
}



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

Restoring Optimizer Statistics

In some cases we may find that gathering fresh statistics has led to the optimizer executing sub-opt...

Performing User-Managed Database-18.5、Restoring Control Files

18.5、Restoring Control Files 18.5.1、Restore Lost Copy of a Multiplexed Control File 18.5.1.1、Copying...

Backing Up and Restoring the Database

Backing Up and Restoring the Database HP Vertica支持一个综合的应用,vbr.py Python script,它的功能包括:back up, rest...

CodeForces 490E Restoring Increasing Sequence

题意: 一个严格递增序列  某些数字的某些位被盖住了  求  恢复后的序列 思路: 贪心  让每个数在大于前一个的基础上尽量的小 先讨论数字长度 len[i] len[i]>len[i-1...

Performing User-Managed Database-18.4、Restoring Datafiles and Archived Redo Logs

18.4、Restoring Datafiles and Archived Redo Logs 如果介质失败损坏一个或多个数据文件,恢复损坏的文件前必须还原数据文件。如果还原的位置不是原始位置,必须在...

Codeforces Round #353 (Div. 2)-B. Restoring Painting(数学)

B. Restoring Painting time limit per test 1 second memory limit per test 256 megabytes ...

Codeforces Round #279 (Div. 2) E. Restoring Increasing Sequence

E. Restoring Increasing Sequence time limit per test 1 second memory limit per test 256 ...

ZOJ 3965 Binary Tree Restoring (递归)

Given two depth-first-search (DFS) sequences of a binary tree, can you find a binary tree which sati...

Codeforces Round #279 (Div. 2)E. Restoring Increasing Sequence

http://codeforces.com/contest/490/problem/E 字符串处理,思路很快出来,找出符合要求的最近的字符串,如果不存在输出-1,但是实现起来却有点麻烦了,写了半天,...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:【cf】Restoring Paintie
举报原因:
原因补充:

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