HDU 3682To Be an Dream Architect(統計規律題目 三線相交bug)
To Be an Dream Architect
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2643 Accepted Submission(s): 753
Problem Description
The “dream architect” is the key role in a team of “dream extractors” who enter other’s dreams to steal secrets. A dream architect is responsible for crafting the virtual world that the team and the target will dream into. To avoid the target noticing the world
is artificial, a dream architect must have powerful 3D imagination.
Cobb uses a simple 3D imagination game to test whether a candidate has the potential to be an dream architect. He lets the candidate imagine a cube consisting of n×n×n blocks in a 3D coordinate system as Figure 1. The block at bottom left front corner is marked (1, 1, 1) and the diagonally opposite block is marked (n, n, n). Then he tells the candidate that the blocks on a certain line are eliminated. The line is always parallel to an axis. After m such block eliminations, the candidate is asked to tell how many blocks are eliminated. Note that one block can only be eliminated once even if it is on multiple lines.
Here is a sample graph according to the first test case in the sample input:

Cobb uses a simple 3D imagination game to test whether a candidate has the potential to be an dream architect. He lets the candidate imagine a cube consisting of n×n×n blocks in a 3D coordinate system as Figure 1. The block at bottom left front corner is marked (1, 1, 1) and the diagonally opposite block is marked (n, n, n). Then he tells the candidate that the blocks on a certain line are eliminated. The line is always parallel to an axis. After m such block eliminations, the candidate is asked to tell how many blocks are eliminated. Note that one block can only be eliminated once even if it is on multiple lines.
Here is a sample graph according to the first test case in the sample input:

Input
The first line is the number of test cases.
In each test case, the first line contains two integers n and m( 1 <= n <= 1000, 0 <= m <= 1000).,meaning that the cube is n x n x n and there are m eliminations.
Each of the following m lines represents an elimination in the following format:
axis_1=a, axis_2=b
where axis_i (i=1, 2) is ‘X’ or ‘Y’, or ‘Z’ and axis_1 is not equal to axis_2. a and b are 32-bit signed integers.
In each test case, the first line contains two integers n and m( 1 <= n <= 1000, 0 <= m <= 1000).,meaning that the cube is n x n x n and there are m eliminations.
Each of the following m lines represents an elimination in the following format:
axis_1=a, axis_2=b
where axis_i (i=1, 2) is ‘X’ or ‘Y’, or ‘Z’ and axis_1 is not equal to axis_2. a and b are 32-bit signed integers.
Output
For each test case output the number of eliminated blocks.
Sample Input
2
3 2
Y=1,Z=3
X=3,Y=1
10 2
X=3,Y=3
Y=3,Z=3
Sample Output
5
19
Source
題目意思不說了,自己的想法是先假使每一條線都能消除n個點,然後再減去那些算重了的。其實當時寫了資料已經驗證到了三點相交只能減去兩次次,但是自己卻按減三次計算。這次組隊賽暴露的問題比較多,不過還好不是現場賽,幸好不是現場賽,是個很大的教訓!!!教訓!
AC程式碼:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
int p[3][1005][3];
int t[3];
int n,m;
map<int,int> mp1,mp2,mp3;
map<int,int> mm;
// x y z
// 0 5 6
// 1 6 7
// 2 5 7
int main()
{
//freopen("in.txt","r",stdin);
char ch1,ch2;
int a,b,i,j;
int tmp1;
int sum;
int tes;
cin>>tes;
while(tes--)
{
cin>>n>>m;
memset(t,0,sizeof(t));
mp1.clear();
mp2.clear();
mp3.clear();
mm.clear();
char s[20];
for(i=1; i<=m; i++)
{
scanf("%s",s);
sscanf(s,"%c=%d,%c=%d",&ch1,&a,&ch2,&b);
if(ch1>ch2)
{
swap(ch1,ch2);
swap(a,b);
}
//cout<<ch1<<" "<<ch2<<endl;
if(a>=1&&a<=n&&b>=1&&b<=n)
{
if(ch1=='X'&&ch2=='Y')
{
tmp1=10000*a+b;
if(!mp1[tmp1])
{
mp1[tmp1]=1;
p[0][t[0]][0]=a;
p[0][t[0]++][1]=b;
}
}
else if(ch1=='Y'&&ch2=='Z')
{
tmp1=10000*a+b;
if(!mp2[tmp1])
{
mp2[tmp1]=1;
p[1][t[1]][1]=a;
p[1][t[1]++][2]=b;
}
}
else
{
tmp1=10000*a+b;
if(!mp3[tmp1])
{
mp3[tmp1]=1;
p[2][t[2]][0]=a;
p[2][t[2]++][2]=b;
}
}
}
}
sum=(t[0]+t[1]+t[2])*n;
//cout<<t[0]<<' '<<t[1]<<" "<<t[2]<<endl;
for(i=0; i<t[0]; i++)
{
for(j=0; j<t[1]; j++)
{
int tmp;
if(p[0][i][1]==p[1][j][1])
{
tmp=p[0][i][0]*1e6+p[0][i][1]*1e3+p[1][j][2];
mm[tmp]=1;
sum--;
}
}
}
for(i=0; i<t[0]; i++)
{
for(j=0; j<t[2]; j++)
{
int tmp;
if(p[0][i][0]==p[2][j][0])
{
tmp=p[2][j][0]*1e6+p[0][i][1]*1e3+p[2][j][2];
if(!mm[tmp])
{
mm[tmp]=1;
sum--;
}
else if(mm[tmp]==1)
{
mm[tmp]=2; //考慮到三點交在一起,只需要考慮減2,而不是減3
sum--;
}
}
}
}
for(i=0; i<t[1]; i++)
{
for(j=0; j<t[2]; j++)
{
int tmp;
if(p[1][i][2]==p[2][j][2])
{
tmp=p[2][j][0]*1e6+p[1][i][1]*1e3+p[1][j][2];
if(!mm[tmp])
{
mm[tmp]=1;
sum--;
}
else if(mm[tmp]==1)
{
mm[tmp]=2;
sum--;
}
}
}
}
cout<<sum<<endl;
}
return 0;
}
/*
5
1 3
Y=1,Z=1
X=1,Z=1
X=1,Y=1
1 0
1 2
X=3,Y=3
Y=3,Z=3
10 3
X=3,Y=3
Y=3,Z=3
X=3,Z=3
10 0
*/
//0MS
其實也可以暴力寫的,把那些用到的點都標記一下,不過當時想的是用三位陣列存,覺得存不下,這些思路當時都應該拿出來討論一下的。直接把所有的點都對映到一維上面去處理即可。
程式碼:
//直接對每個點進行操作
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
const int max1=1005;
const int max2=max1*max1;
int p[max2];
int main()
{
//freopen("in.txt","r",stdin);
int tes;
cin>>tes;
int n,m,i,j,tmp,len,a,b;
char s[20];
char ch1,ch2;
while(tes--)
{
len=0;
scanf("%d%d",&n,&m);
for(j=0; j<m; j++)
{
scanf("%s",s);
sscanf(s,"%c=%d,%c=%d",&ch1,&a,&ch2,&b);
if(ch1>ch2)
{
swap(ch1,ch2);
swap(a,b);
}
if(ch1=='X'&&ch2=='Z')
{
for(i=1; i<=n; i++)
{
tmp=a*max2+i*max1+b;
p[len++]=tmp;
}
}
else if(ch1=='Y'&&ch2=='Z')
{
for(i=1; i<=n; i++)
{
tmp=i*max2+a*max1+b;
p[len++]=tmp;
}
}
else
{
for(i=1; i<=n; i++)
{
tmp=a*max2+b*max1+i;
p[len++]=tmp;
}
}
}
sort(p,p+len);
int t=p[0],ans=1;
for(i=1;i<len;i++)
{
if(p[i]!=t)
{
t=p[i];
ans++;
}
}
cout<<ans<<endl;
}
return 0;
}
//234MS
相關文章
- HDU 6298 Maximum Multiple(找規律)
- HDU 2197 本原串 (規律+快速冪)
- HDU-6415 Rikka with Nash Equilibrium (DP/找規律)UI
- HDU 5795 A Simple Nim (SG函式+打表找規律)函式
- 三、凸透鏡成像規律
- HDU 6415(dp/找規律-2018多校第九場1001)
- HDU1251 統計難題 【字典樹】
- 快三長龍有規律嗎?
- HDU 1792 - A New Change Problem(規律,最大不能組合數及其個數)
- LeetCode1035. 不相交的線LeetCode
- 平衡規律漫談:平衡原則、目標選定與削弱方式
- DREAM TIME
- 打表找規律
- 計算出大小有什麼走勢圖規律
- [計算幾何]圓與三角形是否相交
- 有趣的路燈問題——按規律列印圖形
- Atcoder 題目選做(三)
- 投資市場上不能不知的三個規律
- leedcode-單詞規律
- LeetCode-單詞規律LeetCode
- Android疑難bug統計Android
- 單目線鐳射三維重建
- Dream缺陷跟蹤系統 2.0版本
- python資料統計之禪道bug統計Python
- QOJ7789-一道位運算找規律好題
- 【LeetCode】290. Word Pattern 單詞規律(Easy)(JAVA)每日一題LeetCodeJava每日一題
- 律所管理系統能解決律師事務所存在的這些問題
- HUNAN -11566 Graduation Examination(找規律)NaN
- LeetCode-290-單詞規律LeetCode
- 程式設計題目解析程式設計
- HDU 1542 Atlantis(掃描線)
- 線段樹 transformation——hdu 4578ORM
- [BUG反饋]PDO連線亂碼問題
- HDU 不要62 題解
- HDU - 5879解題文件
- 出行路線規劃系統設計與開發
- LeetCode:動態規劃+貪心題目整理LeetCode動態規劃
- 動態規劃分類題目總結動態規劃
- leetcode題目10之正規表示式匹配LeetCode