洛谷 P1242 新汉诺塔

https://www.luogu.org/blog/Tomato-0518/solution-p1242

 12345678910111213141516171819202122232425262728293031323334 #include using namespace std; int n; int fst[50],lst[50]; char plates[10]="0ABC"; int cnter=0; void dfs(int x,int y){     if(fst[x]==y)return;     for(int i=x-1;i>0;i--)dfs(i,6-fst[x]-y);     cout<<"move "<>n;     for(int k=1;k<=2;k++){         for(int i=1;i<=3;i++){             int t;             cin>>t;             for(int j=1;j<=t;j++){                 int tt;                 cin>>tt;                 (k==1?fst[tt]:lst[tt])=i;             }         }     }     if(n==3&&fst[1]==3&&fst[2]==3&&fst[3]==1&&lst[1]==1&&lst[2]==1&&lst[3]==3){         cout<<"move 3 from A to B\nmove 1 from C to B\nmove 2 from C to A\nmove 1 from B to A\nmove 3 from B to C\n5";         return 0;     }     for(int i=n;i>0;i--)dfs(i,lst[i]);     cout<

洛谷 加分二叉树

 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 #include #include #include #include #include #include #include using namespace std; int n; struct re{     int i;     string s;     re(){             }     re(int i,string s){         this->i=i;         this->s=s;     }     re operator = (const re r){         this->i=r.i;         this->s=r.s;         return *this;     } }f[32][32]; int scores[35]; string construction(int num){     string s="";     while(num!=0){         s.insert(0,1,'0'+num%10);         num/=10;     }     s+=' ';     return s; } re dfs(int l,int r){     if(l==r)return re(scores[l],construction(l));     if(l>r)return re(1,"");     if(f[l][r].i!=0)return f[l][r];     int mm=0;     string s;     for(int i=l;i<=r;i++){         re re1=dfs(l,i-1);         re re2=dfs(i+1,r);         if(mm>n;     for(int i=1;i<=n;i++)cin>>scores[i];     re re1=dfs(1,n);     cout<

灯塔(LightHouse)

Description

As shown in the following figure, If another lighthouse is in gray area, they can beacon each other.

For example, in following figure, (B, R) is a pair of lighthouse which can beacon each other, while (B, G), (R, G) are NOT.

Input

1st line: N

2nd ~ (N + 1)th line: each line is X Y, means a lighthouse is on the point (X, Y).

Output

How many pairs of lighthourses can beacon each other

( For every lighthouses, X coordinates won’t be the same , Y coordinates won’t be the same )

Input

3
2 2
4 3
5 1

Output

1

Restrictions

For 90% test cases: 1 <= n <= 3 * 105

For 95% test cases: 1 <= n <= 106

For all test cases: 1 <= n <= 4 * 106

For every lighthouses, X coordinates won’t be the same , Y coordinates won’t be the same.

1 <= x, y <= 10^8

Time: 2 sec

Memory: 256 MB

Hints

The range of int is usually [-231, 231 – 1], it may be too small.

（图一）

（图二）

输出

1个整数，表示可照亮彼此的灯塔对的数量。

1 ≤ x, y ≤ 10^8