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 3682 To Be an Dream Architect:查重【三維座標系中點在實數上的對映】
- HDU5139 Formula (找規律+離線處理)ORM
- HDU4342 History repeat itself數學規律題
- HDU 6298 Maximum Multiple(找規律)
- HDU 4951 Multiplication table(找規律)
- 數學規律題,數論知識:hdu1792
- HDU 5795 A Simple Nim (SG函式+打表找規律)函式
- HDU 4686 Arc of Dream(矩陣加速遞推)矩陣
- 【計算幾何】線段相交
- HDU-6415 Rikka with Nash Equilibrium (DP/找規律)UI
- HDU 5439 Aggregated Counting(找規律+預處理)
- HDU 2897-邂逅明下(博弈-SG函式打表找規律)函式
- HDU 1166 敵兵佈陣 線段樹入門題目
- HDU 1792 - A New Change Problem(規律,最大不能組合數及其個數)
- HDU 1847 Good Luck in CET-4 Everybody!(找規律版巴什博奕)Go
- HDU 1847-Good Luck in CET-4 Everybody!(博弈-SG函式/找規律)Go函式
- EMS單號規律與順豐單號規律(C#)C#
- 73:字元統計★]題目描述:字元
- 【計算幾何】求線段相交交點座標
- A Multiplication Game (博弈,規律)GAM
- 打表找規律
- 平衡規律漫談:平衡原則、目標選定與削弱方式
- 計算出大小有什麼走勢圖規律
- 程式設計師的成功是否有規律可循?程式設計師
- 艾倫·坡《夢中夢》(A Dream Within A Dream)
- codeforces 340CTourist Problem(找規律數學題)
- sencha architect/sencha touch , to prevent breakpoint lost when you debug
- bugku一道逆向題目分析
- POJ 1127-Jack Straws(計算幾何 線段相交)
- [計算幾何]圓與三角形是否相交
- HDU 4669 Mutiples on a circle (DP , 統計)
- HDU 2017 字串統計字串
- 機器學習之特徵組合: 多非線性規律進行編碼機器學習特徵
- POJ 4048 Chinese Repeating Crossbow(線段相交)ROS
- leedcode-單詞規律
- POJ 1039-Pipe(計算幾何-線段相交、求交點)
- 雲端計算的基本經濟規律及產業鏈分析產業
- HDU 1556 Color the ball 線段樹入門題