USACO section3.1 Shaping Regions(漂浮法)

学生党投稿Applied Soft Computing:从导师账号登录到通讯作者设置的全流程解惑 本文详细解析了学生投稿Applied Soft Computing期刊的全流程,重点介绍了导师账号登录、通讯作者设置、作者排序调整以及开放获取费用等关键环节的避坑技巧。针对LaTeX稿件处理和财务选项选择提供了实用建议,帮助学生顺利完成SCI期刊投稿。 阅读详情

 

 

 

Shaping Regions

N opaque rectangles (1 <= N <= 1000) of various colors are placed on a white sheet of paper whose size is A wide by B long. The rectangles are put with their sides parallel to the sheet's borders. All rectangles fall within the borders of the sheet so that different figures of different colors will be seen.

The coordinate system has its origin (0,0) at the sheet's lower left corner with axes parallel to the sheet's borders.

PROGRAM NAME: rect1

INPUT FORMAT

The order of the input lines dictates the order of laying down the rectangles. The first input line is a rectangle "on the bottom".

 

Line 1:A, B, and N, space separated (1 <= A,B <= 10,000)
Lines 2-N+1:Five integers: llx, lly, urx, ury, color: the lower left coordinates and upper right coordinates of the rectangle whose color is `color' (1 <= color <= 2500) to be placed on the white sheet. The color 1 is the same color of white as the sheet upon which the rectangles are placed.

SAMPLE INPUT (file rect1.in)

20 20 3
2 2 18 18 2
0 8 19 19 3
8 0 10 19 4

INPUT EXPLANATION

Note that the rectangle delineated by 0,0 and 2,2 is two units wide and two high. Here's a schematic diagram of the input:

11111111111111111111
33333333443333333331
33333333443333333331
33333333443333333331
33333333443333333331
33333333443333333331
33333333443333333331
33333333443333333331
33333333443333333331
33333333443333333331
33333333443333333331
33333333443333333331
11222222442222222211
11222222442222222211
11222222442222222211
11222222442222222211
11222222442222222211
11222222442222222211
11111111441111111111
11111111441111111111

The '4's at 8,0 to 10,19 are only two wide, not three (i.e., the grid contains a 4 and 8,0 and a 4 and 8,1 but NOT a 4 and 8,2 since this diagram can't capture what would be shown on graph paper).

OUTPUT FORMAT

The output file should contain a list of all the colors that can be seen along with the total area of each color that can be seen (even if the regions of color are disjoint), ordered by increasing color. Do not display colors with no area.

SAMPLE OUTPUT (file rect1.out)

1 91
2 84
3 187
4 38

HINTS (use them carefully!)

       HINT 1  

 

思路:俗称漂浮法,从最上层开始始逐步向下,而当前层则一直往上飘浮,若碰到长方形则裂成几个长方形。

          最后的面积及飘到水面时剩余的面积。

注意点:输入的相同颜色的长方形可能有多块,并且不一定按照颜色递增输入。所以需处理一下在输出。

不足点:思路是我自己想出来的,可是碰到长方形就裂成几个长方形,一直想不明白咋怎,咋裂,就去百度了,看他人的裂法才知道这就漂浮法。

            准确的来说这不能算是完全原创。

            

 

代码:

 

/*
ID:nealgav1
LANG:C++
PROG:rect1
*/
#include<fstream>
#include<algorithm>
using namespace std;
ifstream cin("rect1.in");
ofstream cout("rect1.out");
const int mm=2600;
class point
{
  public:
  int l,r,u,d;
  int colour,area;
  point(){area=0;colour=0;}
}pos[1200];
int ans[mm];
int cas;
int ce;
void kill(int l,int d,int r,int u,int k)
{ if(k>cas)///漂浮到水面了,可以计算面积了。
   {
     pos[ce].area+=(r-l)*(u-d);return;
   }
   if(l==r||u==d)return;///优化剪枝,面积为0的长方形就不用在裂了。
   ///四个方向的裂法:1:不裂重复,2,不裂没有的面积。
  if(l<pos[k].l)kill(l,min(d,pos[k].u),min(r,pos[k].l),min(u,pos[k].u),k+1);
  if(r>pos[k].r)kill(max(l,pos[k].r),max(pos[k].d,d),r,max(pos[k].d,u),k+1);
  if(u>pos[k].u)kill(min(l,pos[k].r),max(d,pos[k].u),min(r,pos[k].r),u,k+1);
  if(d<pos[k].d)kill(max(l,pos[k].l),d,max(pos[k].l,r),min(pos[k].d,u),k+1);
}
bool cmp(point a,point b)
{
  return a.colour<b.colour;
}
int main()
{
  int m,n;
  fill(ans,ans+mm,0);
  cin>>m>>n>>cas;
  for(int i=1;i<=cas;i++)
  cin>>pos[i].l>>pos[i].d>>pos[i].r>>pos[i].u>>pos[i].colour;
  pos[0].area=m*n;pos[0].colour=1;
  for(int i=cas;i>=1;i--)
  {
    ce=i;kill(pos[i].l,pos[i].d,pos[i].r,pos[i].u,i+1);
    pos[0].area-=pos[ce].area;
    ans[pos[i].colour]+=pos[i].area;///ans[],记录答案,同时省去了排序和,加和处理。
  }
  ans[pos[0].colour]+=pos[0].area;
  for(int i=0;i<mm;i++)
  if(ans[i])
  cout<<i<<" "<<ans[i]<<"\n";
}


 

 

 

 

Shaping Regions
Russ Cox

Analysis by Mathijs Vogelzang

A straightforward approach to this problem would be to make an array which represents the table, and then draw all the rectangles on it. In the end, the program can just count the colors from the array and output them. Unfortunately, the maximum dimensions of this problem are 10,000 x 10,000, which means the program uses 100 million integers. That's too much, so we need another approach.

An approach that does work for such large cases (and it actually is a lot faster too) is to keep track of the rectangles, and delete portions of them when they are covered by other rectangles.

Consider this input set:

0 0 10 10 5
5 0 15 10 10

The program first reads in the first rectangle and puts it in a list. When it reads a new rectangle it checks all items in the list if they overlap with the new rectangle. This is the case, and then it deletes the old rectangle from the list and adds all parts which aren't covered to the list. (So in this case, the program would delete the first rectangle, add 0 0 5 10 5 to the list and then add the second rectangle to the list). ``

If you're unlucky, a new rectangle can create lots of new rectangles (when the new rectangle entirely fits into another one, the program creates four new rectangles which represent the leftover border:

+--------+      +-+--+--+
|        |      | |2 |  |
|        |      + +--+  |
|  +-+   |  --> | |  |  |
|  +-+   |      |1|  |3 |
|        |      | +--+  |
|        |      | | 4|  |
+--------+      +-+--+--+

This is not a problem however, because there can be only 2500 rectangles and there is plenty of memory, so rectangles have to be cut very much to run out of memory.

Note that with this approach, the only thing that matters is how many rectangles there are and how often they overlap. The maximum dimensions can be as large as you want, it doesn't matter for the running time.

Further Analysis by Tomek Czajka

There is another solution to this problem, which runs in O(n*n*log n) time, but is quite tricky. First, we add one big white rectangle at the bottom - the paper. Then we make two arrays: one containing all vertical edges of the rectangles, and the other the horizontal ones. For each edge we have its coordinates and remember, whether it's the left or right edge (top or bottom). We sort these edges from left to right and from top to bottom. Then we go from left to right (sweep), jumping to every x-coordinate of vertical edges. At each step we update the set of rectangles seen. We also want to update the amount of each color seen so far. So for each x we go from top to bottom, for each y updating the set of rectagles at a point (in the structure described below) and choosing the top one, so that we can update the amounts of colors seen.

The structure to hold the set of rectangles at a point should allow adding a rectangle (number from 1..1000), deleting a rectangle, and finding the top one. We can implement these operations in O(log n) time if we use a heap. To make adding and deleting run in O(log n) we must also have for each rectangle its position in the heap.

So the total time spent at each point is O(log n). Thus the algorithm works in O(n*n*log n) time.

And a solution from mrsigma:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

FILE *fp,*fo;

struct rect
{
    int c;
    int x1,y1,x2,y2;
};

int c[2501];
rect r[10001];

int intersect(rect a,const rect &b,rect out[4])
{
    /* do they at all intersect? */
    if(b.x2<a.x1||b.x1>=a.x2)
        return 0;
    if(b.y2<a.y1||b.y1>=a.y2)
        return 0;
    /* they do */

    rect t;

    if(b.x1<=a.x1&&b.x2>=a.x2&&b.y1<=a.y1&&b.y2>=a.y2)
            return -1;

    /* cutting `a' down to match b */
    int nout=0;
    if(b.x1>=a.x1) {
        t=a,t.x2=b.x1;
        if(t.x1!=t.x2)
            out[nout++]=t;
        a.x1=b.x1;
    }
    if(b.x2<a.x2) {
        t=a,t.x1=b.x2;
        if(t.x1!=t.x2)
            out[nout++]=t;
        a.x2=b.x2;
    }
    if(b.y1>=a.y1) {
        t=a,t.y2=b.y1;
        if(t.y1!=t.y2)
            out[nout++]=t;
        a.y1=b.y1;
    }
    if(b.y2<a.y2) {
        t=a,t.y1=b.y2;
        if(t.y1!=t.y2)
            out[nout++]=t;
        a.y2=b.y2;
    }
    return nout;
}

int main(void) {
    fp=fopen("rect1.in","rt");
    fo=fopen("rect1.out","wt");

    int a,b,n;
    fscanf(fp,"%d %d %d",&a,&b,&n);

    r[0].c=1;
    r[0].x1=r[0].y1=0;
    r[0].x2=a;
    r[0].y2=b;

    rect t[4];

    int i,j,rr=1;
    for(i=0;i<n;i++) {
        int tmp;
        fscanf(fp,"%d %d %d %d %d",&r[rr].x1,&r[rr].y1,&r[rr].x2,&r[rr].y2,&r[rr].c);

        if(r[rr].x1>r[rr].x2) {
            tmp=r[rr].x1;
            r[rr].x1=r[rr].x2;
            r[rr].x2=tmp;
        }
        if(r[rr].y1>r[rr].y2) {
            tmp=r[rr].y1;
            r[rr].y1=r[rr].y2;
            r[rr].y2=tmp;
        }

        int nr=rr;
        rect curr=r[rr++];
        for(j=0;j<nr;j++) {
            int n=intersect(r[j],curr,t);
            if(!n)
                continue;
            if(n==-1) {
                memmove(r+j,r+j+1,sizeof(rect)*(rr-j-1));
                j--;
                rr--;
                nr--;
                continue;
            }
            r[j]=t[--n];
            for(;n-->0;)
                r[rr++]=t[n];
        }
    }

    for(i=0;i<rr;i++)
        c[r[i].c]+=(r[i].x2-r[i].x1)*(r[i].y2-r[i].y1);

    for(i=1;i<=2500;i++)
        if(c[i])
            fprintf(fo,"%d %d\n",i,c[i]);

    return 0;
}

And another fast solution from Saber Fadaee:

In Shaping Regions, I changed the whole A*B page into (2*N) * (2*N).

  Program rrect1;
  Var
    Inf,Outf            : Text;
    A,B,N,I,Z,Middle,J  : Longint;
    Color               : Array [1..2500] of Longint;
    D                   : Array [1..5000,1..5000] of boolean;
    Xar,Yar             : Array [0..2500] of Longint;
    Col                 : Array [1..10000] of Record
                                               x1 : Longint;
                                               x2 : Longint;
                                               y1 : Longint;
                                               y2 : Longint;
                                               c  : Longint;
                                             End;

  Function Find (K1 : integer) : Longint;
  Var
    Pointer,N1,N2                          : Longint;
  Begin
    N1 := 1;
    N2 := N + N;
    While N1 > 0 Do Begin
        Pointer := (N1 + N2) Div 2;
        If Xar[Pointer] = K1 then Begin
           Find := Pointer;
           Exit;
        End;
        If Xar[Pointer] > K1 Then
          N2 := Pointer - 1;
        If Xar[Pointer] < K1 Then
          N1 := Pointer + 1;
    End;
  End;

  Function Find1 (K2 : Longint) : Longint;
  Var
    Pointer,N1,N2                          : Longint;
  Begin
    N1 := 1;
    N2 := N + N;
    While N1 > 0 Do Begin
        Pointer := (N1 + N2) Div 2;
        If Yar[Pointer] = K2 then Begin
           Find1 := Pointer;
           Exit;
        End;
        If Yar[Pointer] > K2 Then
          N2 := Pointer - 1;
        If Yar[Pointer] < K2 Then
          N1 := Pointer + 1;
    End;
  End;

  Procedure Partition1 ( Lf , Rg : Longint );
  Var
    Pivot,L,R,Temp                 : Longint;
  Begin
    Pivot := Yar[Lf];
    L := Lf;
    R := Rg;
    While L < R Do Begin
        While (Yar[L] <= Pivot) and (L <= R) Do Inc(L);
        While (Yar[R] > Pivot) And (R >= L) Do Dec(R);
        If L < R Then
          begin
            Temp := Yar[L];
            Yar[L] := Yar[R];
            Yar[R] := Temp;
          end;
      End;
      Middle := R;
      Temp := Yar[Lf];
      Yar[Lf] := Yar[R];
      Yar[R] := Temp;
  End;

  Procedure QSort1 ( Left , Right : Longint );
  Begin
    if Left < Right Then
      Begin
        Partition1 (Left,Right);
        QSort1 (Left,Middle-1);
        QSort1 (Middle + 1, Right);
      End;
  End;

  Procedure Partition ( Lf , Rg : Longint );
  Var
    Pivot,L,R,Temp              : Longint;
  Begin
    Pivot := Xar[Lf];
    L := Lf;
    R := Rg;
    While L < R Do
      Begin
        While (Xar[L] <= Pivot) and (L <= R) Do Inc(L);
        While (Xar[R] > Pivot) And (R >= L) Do Dec(R);
        If L < R Then
          begin
            Temp := Xar[L];
            Xar[L] := Xar[R];
            Xar[R] := Temp;
          end;
      End;
      Middle := R;
      Temp := Xar[Lf];
      Xar[Lf] := Xar[R];
      Xar[R] := Temp;
  End;

  Procedure QSort ( Left , Right : Longint );
  Begin
    if Left < Right Then
      Begin
        Partition (Left,Right);
        QSort (Left,Middle-1);
        QSort (Middle + 1, Right);
      End;
  End;


  Begin
    Assign (Inf ,'rect1.in');
    Reset (Inf);
    Readln (Inf,A,B,N);
    For I := 1 To N Do
        Readln (Inf , Col[I].x1,col[i].y1,col[i].x2,col[i].y2,col[i].c);
    Close (Inf);
    For I := 1 to 2500 do Color[I] := 0;
    Color[1] := A * B;
    For I := 0 to n do
      For J := 0 to n do
        D[I,J] := False;
    Xar[0] := 0;
    Xar[n+n+1] := a;
    For I := 1 To N do Xar[i] := Col[i].x1;
    For I := N + 1 To N + N do Xar[i] := Col[i - n].x2;
      Qsort (1,N + N);
    Yar[0] := 0;
    Yar[n+n+1] := b;
    For I := 1 To N Do Yar[i] := Col[i].y1;
    For I := N + 1 To N + N do Yar[i] := col[i - n].y2;
      Qsort1 (1,N + N);
    For I := N Downto 1 Do
      For J := find(Col[i].x1) + 1 to find(col[i].x2) do
        For Z := find1(col[i].y1) + 1 to find1(col[i].y2) do
          If not D[J,Z] then
            Begin
              If col[i].c > 1 then
                Begin
                  Middle := (Xar[j] - Xar[j-1]) * (Yar[z] - Yar[z-1]);
                  Color[Col[i].c] := color[Col[i].c] + Middle;
                  Color[1] := Color[1] - Middle;
                End;
              D[J,Z] := True;
            End;
    Assign (Outf, 'rect1.out');
    Rewrite (Outf);
    For I := 1 To 2500 Do
      if color[i] > 0 then
        Writeln (Outf,i,' ', Color[i]);
    Close(Outf);
  End.

And, finally, an unbelievably compact recursive solution from Christoph Roick:

This solution uses recursion. We start with painting the last rectangle and go through to the first (the white paper). We save the edges of every rectangle, because we shouldn't paint over the rectangles above it. Now we have to divide the rectangles in 0 to 4 pieces around the rectangles covering it. In the end we have a lot of small rectangles and the colors can be added to an array by calculating the areas of the rectangle. So, we won't get any problems concerning too less memory.

program rect1;

var F: Text;
    i,a,b,n,cused,maxcolor:word;
    inform: array[1..1001,1..5] of word;
    used: array[1..1001,1..4] of word;
    countcolor: array[1..2500] of longint;

procedure cac(count,x1,y1,x2,y2,color: word); //cut and count
var py1,py2 : word;
begin
    if count<cused then begin
        if (x1>used[count,3]) or (x2<used[count,1]) or (y1>used[count,4]) or (y2<used[count,2]) then
            cac(succ(count),x1,y1,x2,y2,color)  //if there are no difficulties with the other rectangle
        else begin
            if y1>used[count,2] then py1:=y1 else py1:=used[count,2];
            if y2<used[count,4] then py2:=y2 else py2:=used[count,4];
            if y1<used[count,2] then cac(succ(count),x1,y1,x2,pred(used[count,2]),color);
            if y2>used[count,4] then cac(succ(count),x1,succ(used[count,4]),x2,y2,color);
            if x1<used[count,1] then cac(succ(count),x1,py1,pred(used[count,1]),py2,color);
            if x2>used[count,3] then cac(succ(count),succ(used[count,3]),py1,x2,py2,color);
        end;
    end else inc(countcolor[color],succ(x2-x1)*succ(y2-y1));
end;

begin
    Assign(F,'rect1.in');
    Reset(F);
    Readln(F,a,b,n);
    inc(n);
    for i:=2 to n do
        Readln(F,inform[i,1],inform[i,2],inform[i,3],inform[i,4],inform[i,5]);  //x1,y1,x2,y2,color
    Close(F);
    inform[1,1]:=0; inform[1,2]:=0; //white paper
    inform[1,3]:=a; inform[1,4]:=b; inform[1,5]:=1;
    maxcolor:=1;
    cused:=1;

    for i:=n downto 1 do begin
        cac(1,inform[i,1],inform[i,2],pred(inform[i,3]),pred(inform[i,4]),inform[i,5]);
        if inform[i,5]>maxcolor then maxcolor:=inform[i,5];  //we don't have to check all 2500 colors
        used[cused,1]:=inform[i,1];  //saving the coordinates of the rectangle
        used[cused,2]:=inform[i,2];
        used[cused,3]:=pred(inform[i,3]);
        used[cused,4]:=pred(inform[i,4]);
        inc(cused);
    end;

    Assign(F,'rect1.out');
    Rewrite(F);
    for i:=1 to maxcolor do
        if countcolor[i]>0 then
            Writeln(F,i,' ',countcolor[i]);
  Close(F);
end.

 


Shaping Regions
Russ Cox

Analysis by Mathijs Vogelzang

A straightforward approach to this problem would be to make an array which represents the table, and then draw all the rectangles on it. In the end, the program can just count the colors from the array and output them. Unfortunately, the maximum dimensions of this problem are 10,000 x 10,000, which means the program uses 100 million integers. That's too much, so we need another approach.

An approach that does work for such large cases (and it actually is a lot faster too) is to keep track of the rectangles, and delete portions of them when they are covered by other rectangles.

Consider this input set:

0 0 10 10 5
5 0 15 10 10

The program first reads in the first rectangle and puts it in a list. When it reads a new rectangle it checks all items in the list if they overlap with the new rectangle. This is the case, and then it deletes the old rectangle from the list and adds all parts which aren't covered to the list. (So in this case, the program would delete the first rectangle, add 0 0 5 10 5 to the list and then add the second rectangle to the list). ``

If you're unlucky, a new rectangle can create lots of new rectangles (when the new rectangle entirely fits into another one, the program creates four new rectangles which represent the leftover border:

+--------+      +-+--+--+
|        |      | |2 |  |
|        |      + +--+  |
|  +-+   |  --> | |  |  |
|  +-+   |      |1|  |3 |
|        |      | +--+  |
|        |      | | 4|  |
+--------+      +-+--+--+

This is not a problem however, because there can be only 2500 rectangles and there is plenty of memory, so rectangles have to be cut very much to run out of memory.

Note that with this approach, the only thing that matters is how many rectangles there are and how often they overlap. The maximum dimensions can be as large as you want, it doesn't matter for the running time.

Further Analysis by Tomek Czajka

There is another solution to this problem, which runs in O(n*n*log n) time, but is quite tricky. First, we add one big white rectangle at the bottom - the paper. Then we make two arrays: one containing all vertical edges of the rectangles, and the other the horizontal ones. For each edge we have its coordinates and remember, whether it's the left or right edge (top or bottom). We sort these edges from left to right and from top to bottom. Then we go from left to right (sweep), jumping to every x-coordinate of vertical edges. At each step we update the set of rectangles seen. We also want to update the amount of each color seen so far. So for each x we go from top to bottom, for each y updating the set of rectagles at a point (in the structure described below) and choosing the top one, so that we can update the amounts of colors seen.

The structure to hold the set of rectangles at a point should allow adding a rectangle (number from 1..1000), deleting a rectangle, and finding the top one. We can implement these operations in O(log n) time if we use a heap. To make adding and deleting run in O(log n) we must also have for each rectangle its position in the heap.

So the total time spent at each point is O(log n). Thus the algorithm works in O(n*n*log n) time.

And a solution from mrsigma:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

FILE *fp,*fo;

struct rect
{
    int c;
    int x1,y1,x2,y2;
};

int c[2501];
rect r[10001];

int intersect(rect a,const rect &b,rect out[4])
{
    /* do they at all intersect? */
    if(b.x2<a.x1||b.x1>=a.x2)
        return 0;
    if(b.y2<a.y1||b.y1>=a.y2)
        return 0;
    /* they do */

    rect t;

    if(b.x1<=a.x1&&b.x2>=a.x2&&b.y1<=a.y1&&b.y2>=a.y2)
            return -1;

    /* cutting `a' down to match b */
    int nout=0;
    if(b.x1>=a.x1) {
        t=a,t.x2=b.x1;
        if(t.x1!=t.x2)
            out[nout++]=t;
        a.x1=b.x1;
    }
    if(b.x2<a.x2) {
        t=a,t.x1=b.x2;
        if(t.x1!=t.x2)
            out[nout++]=t;
        a.x2=b.x2;
    }
    if(b.y1>=a.y1) {
        t=a,t.y2=b.y1;
        if(t.y1!=t.y2)
            out[nout++]=t;
        a.y1=b.y1;
    }
    if(b.y2<a.y2) {
        t=a,t.y1=b.y2;
        if(t.y1!=t.y2)
            out[nout++]=t;
        a.y2=b.y2;
    }
    return nout;
}

int main(void) {
    fp=fopen("rect1.in","rt");
    fo=fopen("rect1.out","wt");

    int a,b,n;
    fscanf(fp,"%d %d %d",&a,&b,&n);

    r[0].c=1;
    r[0].x1=r[0].y1=0;
    r[0].x2=a;
    r[0].y2=b;

    rect t[4];

    int i,j,rr=1;
    for(i=0;i<n;i++) {
        int tmp;
        fscanf(fp,"%d %d %d %d %d",&r[rr].x1,&r[rr].y1,&r[rr].x2,&r[rr].y2,&r[rr].c);

        if(r[rr].x1>r[rr].x2) {
            tmp=r[rr].x1;
            r[rr].x1=r[rr].x2;
            r[rr].x2=tmp;
        }
        if(r[rr].y1>r[rr].y2) {
            tmp=r[rr].y1;
            r[rr].y1=r[rr].y2;
            r[rr].y2=tmp;
        }

        int nr=rr;
        rect curr=r[rr++];
        for(j=0;j<nr;j++) {
            int n=intersect(r[j],curr,t);
            if(!n)
                continue;
            if(n==-1) {
                memmove(r+j,r+j+1,sizeof(rect)*(rr-j-1));
                j--;
                rr--;
                nr--;
                continue;
            }
            r[j]=t[--n];
            for(;n-->0;)
                r[rr++]=t[n];
        }
    }

    for(i=0;i<rr;i++)
        c[r[i].c]+=(r[i].x2-r[i].x1)*(r[i].y2-r[i].y1);

    for(i=1;i<=2500;i++)
        if(c[i])
            fprintf(fo,"%d %d\n",i,c[i]);

    return 0;
}

And another fast solution from Saber Fadaee:

In Shaping Regions, I changed the whole A*B page into (2*N) * (2*N).

  Program rrect1;
  Var
    Inf,Outf            : Text;
    A,B,N,I,Z,Middle,J  : Longint;
    Color               : Array [1..2500] of Longint;
    D                   : Array [1..5000,1..5000] of boolean;
    Xar,Yar             : Array [0..2500] of Longint;
    Col                 : Array [1..10000] of Record
                                               x1 : Longint;
                                               x2 : Longint;
                                               y1 : Longint;
                                               y2 : Longint;
                                               c  : Longint;
                                             End;

  Function Find (K1 : integer) : Longint;
  Var
    Pointer,N1,N2                          : Longint;
  Begin
    N1 := 1;
    N2 := N + N;
    While N1 > 0 Do Begin
        Pointer := (N1 + N2) Div 2;
        If Xar[Pointer] = K1 then Begin
           Find := Pointer;
           Exit;
        End;
        If Xar[Pointer] > K1 Then
          N2 := Pointer - 1;
        If Xar[Pointer] < K1 Then
          N1 := Pointer + 1;
    End;
  End;

  Function Find1 (K2 : Longint) : Longint;
  Var
    Pointer,N1,N2                          : Longint;
  Begin
    N1 := 1;
    N2 := N + N;
    While N1 > 0 Do Begin
        Pointer := (N1 + N2) Div 2;
        If Yar[Pointer] = K2 then Begin
           Find1 := Pointer;
           Exit;
        End;
        If Yar[Pointer] > K2 Then
          N2 := Pointer - 1;
        If Yar[Pointer] < K2 Then
          N1 := Pointer + 1;
    End;
  End;

  Procedure Partition1 ( Lf , Rg : Longint );
  Var
    Pivot,L,R,Temp                 : Longint;
  Begin
    Pivot := Yar[Lf];
    L := Lf;
    R := Rg;
    While L < R Do Begin
        While (Yar[L] <= Pivot) and (L <= R) Do Inc(L);
        While (Yar[R] > Pivot) And (R >= L) Do Dec(R);
        If L < R Then
          begin
            Temp := Yar[L];
            Yar[L] := Yar[R];
            Yar[R] := Temp;
          end;
      End;
      Middle := R;
      Temp := Yar[Lf];
      Yar[Lf] := Yar[R];
      Yar[R] := Temp;
  End;

  Procedure QSort1 ( Left , Right : Longint );
  Begin
    if Left < Right Then
      Begin
        Partition1 (Left,Right);
        QSort1 (Left,Middle-1);
        QSort1 (Middle + 1, Right);
      End;
  End;

  Procedure Partition ( Lf , Rg : Longint );
  Var
    Pivot,L,R,Temp              : Longint;
  Begin
    Pivot := Xar[Lf];
    L := Lf;
    R := Rg;
    While L < R Do
      Begin
        While (Xar[L] <= Pivot) and (L <= R) Do Inc(L);
        While (Xar[R] > Pivot) And (R >= L) Do Dec(R);
        If L < R Then
          begin
            Temp := Xar[L];
            Xar[L] := Xar[R];
            Xar[R] := Temp;
          end;
      End;
      Middle := R;
      Temp := Xar[Lf];
      Xar[Lf] := Xar[R];
      Xar[R] := Temp;
  End;

  Procedure QSort ( Left , Right : Longint );
  Begin
    if Left < Right Then
      Begin
        Partition (Left,Right);
        QSort (Left,Middle-1);
        QSort (Middle + 1, Right);
      End;
  End;


  Begin
    Assign (Inf ,'rect1.in');
    Reset (Inf);
    Readln (Inf,A,B,N);
    For I := 1 To N Do
        Readln (Inf , Col[I].x1,col[i].y1,col[i].x2,col[i].y2,col[i].c);
    Close (Inf);
    For I := 1 to 2500 do Color[I] := 0;
    Color[1] := A * B;
    For I := 0 to n do
      For J := 0 to n do
        D[I,J] := False;
    Xar[0] := 0;
    Xar[n+n+1] := a;
    For I := 1 To N do Xar[i] := Col[i].x1;
    For I := N + 1 To N + N do Xar[i] := Col[i - n].x2;
      Qsort (1,N + N);
    Yar[0] := 0;
    Yar[n+n+1] := b;
    For I := 1 To N Do Yar[i] := Col[i].y1;
    For I := N + 1 To N + N do Yar[i] := col[i - n].y2;
      Qsort1 (1,N + N);
    For I := N Downto 1 Do
      For J := find(Col[i].x1) + 1 to find(col[i].x2) do
        For Z := find1(col[i].y1) + 1 to find1(col[i].y2) do
          If not D[J,Z] then
            Begin
              If col[i].c > 1 then
                Begin
                  Middle := (Xar[j] - Xar[j-1]) * (Yar[z] - Yar[z-1]);
                  Color[Col[i].c] := color[Col[i].c] + Middle;
                  Color[1] := Color[1] - Middle;
                End;
              D[J,Z] := True;
            End;
    Assign (Outf, 'rect1.out');
    Rewrite (Outf);
    For I := 1 To 2500 Do
      if color[i] > 0 then
        Writeln (Outf,i,' ', Color[i]);
    Close(Outf);
  End.

And, finally, an unbelievably compact recursive solution from Christoph Roick:

This solution uses recursion. We start with painting the last rectangle and go through to the first (the white paper). We save the edges of every rectangle, because we shouldn't paint over the rectangles above it. Now we have to divide the rectangles in 0 to 4 pieces around the rectangles covering it. In the end we have a lot of small rectangles and the colors can be added to an array by calculating the areas of the rectangle. So, we won't get any problems concerning too less memory.

program rect1;

var F: Text;
    i,a,b,n,cused,maxcolor:word;
    inform: array[1..1001,1..5] of word;
    used: array[1..1001,1..4] of word;
    countcolor: array[1..2500] of longint;

procedure cac(count,x1,y1,x2,y2,color: word); //cut and count
var py1,py2 : word;
begin
    if count<cused then begin
        if (x1>used[count,3]) or (x2<used[count,1]) or (y1>used[count,4]) or (y2<used[count,2]) then
            cac(succ(count),x1,y1,x2,y2,color)  //if there are no difficulties with the other rectangle
        else begin
            if y1>used[count,2] then py1:=y1 else py1:=used[count,2];
            if y2<used[count,4] then py2:=y2 else py2:=used[count,4];
            if y1<used[count,2] then cac(succ(count),x1,y1,x2,pred(used[count,2]),color);
            if y2>used[count,4] then cac(succ(count),x1,succ(used[count,4]),x2,y2,color);
            if x1<used[count,1] then cac(succ(count),x1,py1,pred(used[count,1]),py2,color);
            if x2>used[count,3] then cac(succ(count),succ(used[count,3]),py1,x2,py2,color);
        end;
    end else inc(countcolor[color],succ(x2-x1)*succ(y2-y1));
end;

begin
    Assign(F,'rect1.in');
    Reset(F);
    Readln(F,a,b,n);
    inc(n);
    for i:=2 to n do
        Readln(F,inform[i,1],inform[i,2],inform[i,3],inform[i,4],inform[i,5]);  //x1,y1,x2,y2,color
    Close(F);
    inform[1,1]:=0; inform[1,2]:=0; //white paper
    inform[1,3]:=a; inform[1,4]:=b; inform[1,5]:=1;
    maxcolor:=1;
    cused:=1;

    for i:=n downto 1 do begin
        cac(1,inform[i,1],inform[i,2],pred(inform[i,3]),pred(inform[i,4]),inform[i,5]);
        if inform[i,5]>maxcolor then maxcolor:=inform[i,5];  //we don't have to check all 2500 colors
        used[cused,1]:=inform[i,1];  //saving the coordinates of the rectangle
        used[cused,2]:=inform[i,2];
        used[cused,3]:=pred(inform[i,3]);
        used[cused,4]:=pred(inform[i,4]);
        inc(cused);
    end;

    Assign(F,'rect1.out');
    Rewrite(F);
    for i:=1 to maxcolor do
        if countcolor[i]>0 then
            Writeln(F,i,' ',countcolor[i]);
  Close(F);
end.

 

 

ArcGIS中根据DEM和地形起伏度进行地貌分类划分 大家好我是GIS蒲公英,数字高程模型(digital elevation model, DEM)经常都被用到专题地图的底图中,下面来我们来交流一下仅选择海拔和地形起伏度两个指标,用DEM来进行地貌类型的自动判别划分 阅读详情

相关推荐

(一)利用Python实现数据集读取,Python基本文件操作介绍

机器学习是计算机对大量数据的分析过程,在机器学习的实际项目中,通常都需要准备数据集,数据集通常包含的数据数量是庞大的。例如,在处理计算机视觉领域的项目时,每一张图片都是一个单独的文件,为了提高模型训练的效果,图片数量通常会比较多,因此需要合理且高效的操作将所有的图片数据读取。本篇旨在介绍如何用Python对海量文件进行遍历,也是机器学习实践的第一步。.........

ZZR2631574030的博客 6361

[矩形切割][离散化][usaco3.1.4]Shaping Regions

Shaping Regions形成的区域 译 by tim green 目录  [隐藏]  1 描述2 格式3 SAMPLE INPUT4 SAMPLE OUTPUT5 INPUT EXPLANATION6 HINTS(谨慎地使用它们!) [编辑]描述 N个不同的颜色的不透明的长方形(1 [编辑]格式 PROGR

wu_yihao的专栏 1092

智能车竞赛循迹控制:基于状态机的直道、弯道、十字路口处理策略

在嵌入式系统与自动控制领域,PID控制算法是实现精确运动控制的基础。其原理是通过比例、积分、微分三个环节的线性组合,对系统误差进行实时校正,从而实现对目标值的快速、稳定跟踪。这项技术的核心价值在于为各类自动控制系统提供了稳定、可靠且易于实现的解决方案,广泛应用于机器人、无人机、工业自动化等场景。在智能车循迹这类特定应用中,赛道环境复杂多变,单一的PID控制器难以应对直道、弯道、十字路口等不同赛道元素的控制需求。此时,有限状态机(FSM)作为一种高效的**决策框架**,能够根据实时感知的赛道特征(如边线曲率、

weixin_34034261的博客 294

Usaco Training Section 6.2Shaping Regions

Shaping Regions 形成的区域 N 个不同的颜色的不透明的长方形(1 &lt;= N &lt;= 1000)被放置在一张宽为A 长为B 的白纸上.这 些长方形被放置时,保证了它们的边于白纸的边缘平行.所有的长方形都放置在白纸内,所以我们会看到不同形状的各种颜色.坐标系统的原点(0,0)设在这张白纸的左下角,而坐标轴则平行于边缘. PROGRAM NAME: rect1 INPUT FO...

Monster的博客 414

SAP Parallel Accounting(平行分类账业务)配置及操作手册【适用于多国家会计准则】

在SAP系统中,分类账(Ledger)是用于会计核算的核心概念,它允许企业根据不同的会计原则和货币进行财务记录。定义分类账是配置平行账(Parallel Accounting)的第一步。分类账的创建:通过事务代码OX18可以创建新的分类账。通常,一个SAP系统会有一个主分类账(如0L),它代表法定会计和实时传输至管理会计(CO)的账本。分类账属性:在创建分类账时,需要定义其属性,如会计年度变式、货币、会计原则等。这些属性将决定分类账的核算规则和适用性。

数字化2025 4656

RAG——RAG 索引(文档解析技术)

本文介绍了RAG系统中文档解析的关键技术,重点分析了如何通过LangChain的Document Loaders处理多种格式文档。文章指出高质量文档解析对RAG系统效果的决定性作用,并详细讲解了PDF、TXT、Word等常见格式的解析方法。作者提供了代码示例和Gitee开源项目链接,特别强调了PDF解析的深入方案,同时介绍了相关依赖库的安装配置。文章还展示了如何定义通用文档加载方法,为开发者提供了实用的技术参考。

小志的博客 783

USACO 3.1.4 Shaping Regions

比较基础的矩形切割。 是POJ 2528 Mayor's posters的二维版。 还是要注意边缘的情况,比如当(0,8)(18,18) 切割(18,0)(19,19)的时候,结果应该是得到三个矩形 (18,19)(18,19) --> 面积为1 (19,0)(19,19) --> 面积为20 (18,0)(18,7) --> 面积为8 恩,其实我一直没搞懂为啥给数据...

weixin_30624825的博客 141

XCTF-L3HCTF2021 DeepDarkFantasy write up

XCTF-L3HCTF2021 DeepDarkFantasy write up DeepDarkFantasy 题目描述和hint如下 原始附件如下: 链接:https://pan.baidu.com/s/1Rs1A6viKUXuNvxExAvtvSQ 提取码:lqln 下载后得到一个pth文件,根据第一个提示,其被以简单异或的方式加密,遍历得到解密比特为0xde,此时可以发现PK头 解密后的文件如下: 链接:https://pan.baidu.com/s/1fTiS7DzQP_Rpv_fkB5Ct

qq_42940521的博客 5476

Shaping Regions解题报告

Shaping Regions解题报告 原题:        N个不同的颜色的不透明的长方形(1        这些长方形被放置时,保证了它们的边于白纸的边缘平行。        所有的长方形都放置在白纸内,所以我们会看到不同形状的各种颜色。        坐标系统的原点(0,0)设在这张白纸的左下角,而坐标轴则平行于边缘。 PROGRAM NAME: rect1 INPUT FO

... 781

ios快捷指令进行钉钉打卡

首先 1、打开快捷指令 2、自动化 3、创建个人自动化-特定时间 4、添加操作-搜索“随机数” 5、最小值和最大值填充 6、添加操作-搜索“等待” 7、长按“1秒钟”,选择魔法变量,选择上一步的随机数 6、添加操作-搜索“钉钉” 7、选择钉钉-随便一个聊天窗口。 8、添加操作-搜索“等待”,这次将等待时间设为10秒 9、添加操作 “搜索天气” ,选择显示天气。 注意点: 1、此操作依赖于钉钉极速打卡,只是帮忙唤起钉钉。 2、保存自动化时有个运行前询问,务必关掉。 3、手机不能设

blaze_jack 5万+

NC65实现Restful接口开发及调试

NC65实现Restful接口开发及调试

linzhongshu的专栏 2155

Shaping Regions

###这是本蒟蒻第一次写题解,各位大佬看了勿喷。 拿到题目第一反应是什么?开个数组模拟白纸,将“纸”初始化为1,再根据题目要求一步一步来,将长方形覆盖到纸上(类似于染色),n步染完后可以再统计。似乎没什么问题。 试一试吧: #include&amp;lt;bits/stdc++.h&amp;gt; using namespace std; const int twx=1000+100; const int tt=...

weixin_44351585的博客 402

YOLO26魔改神技:YOLO26引入SimAM(无参注意力):不增加网络参数的3D能量函数提点黑科技

文章摘要 2026年YOLO26模型发布引发边缘计算革命,但特定场景精度不足问题催生注意力机制改进需求。本文聚焦无参数注意力机制SimAM,基于神经科学理论通过3D能量函数直接计算神经元权重,实现零参数量提升模型性能。文章深度解析YOLO26四大创新架构,对比SimAM与传统注意力机制差异,并探讨其在YOLO26中的集成方案。研究显示,SimAM在不增加模型体积前提下显著提升mAP指标,特别适合边缘端部署。全文涵盖架构设计、代码实现、竞品对比、部署方案等维度,为轻量化视觉模型优化提供系统解决方案。

ZDQ58818的博客 280

USACO Section 3.1 Shaping Regions

Shaping Regions N opaque rectangles (1 <= N <= 1000) of various colors are placed on a white sheet of paper whose size is A wide by B long. The rectangles are put with their sides para...

angtongyou1893的博客 185

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain&#39;s apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath(&#39;DeepLearnToolbox&#39;));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand(&#39;state&#39;,0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = &#39;sigm&#39;;%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, &#39;Too big error&#39;);```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, &#39;Too big error&#39;);```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

USACO Section 3.1 Shaping Regions - 矩阵切割..

开始听对里的大大说这是二维线段树..没敢写..后来再一想..数据范围N      就让他这么切..为了防止一些切出来不满足要求或者切出来面积为0没有意义的区域..那么就在递归的时候加个判断.看当前的矩形是否是合法的..也就是lx     Program: /* ID: zzyzzy12 LANG: C++ TASK: rect1 */ #include

zzyzzy12 1500

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

USACO Training Section 3.1 Shaping Regions

[url="http://ace.delos.com/usacoprob2?a=S0UpDJ1JbTn&S=rect1"]英文原题[/url] [url="http://www.wzoi.org/usaco/12%5C103.asp"]中文题译[/url] 大意:在一张白色大纸上放若干个不透明的矩形纸片,每个纸片有一种颜色(可以是白色),这样,有重叠的话,后放的纸片的颜色覆盖了之前的颜色...

山中竹笋 216

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

usaco Chapter 3 section 3.1 Shaping Regions

 /*N opaque rectangles (1 The coordinate system has its origin (0,0) at the sheets lower left corner with axes parallel to the sheets borders.   这个题目就是传说中的难题,我没有思路,看看网上的做法,也搞不懂。什么线段树,我还没有了解。什么

china1000的专栏 531

USACO SECTION 3.1 Shaping Regions

Shaping Regions N opaque rectangles (1 <= N <= 1000) of various colors are placed on a white sheet of paper whose size is A wide by B long. The rectangles are put with their sides parallel to the s

363

Section 3.1 Shaping Regions

卡这题卡了一天左右,不会做额,找了不少的代码和解说,发现NOCOW这里很不错,有大牛在这里写方法,可以拓宽思路,这几个1,2,3还不错,看懂了,和HDU1543是同一道题,就说说题意和方法吧。 给定一个A*B的矩形,A<10^4,B<10^4,然后可以往这个矩形上涂矩形状的颜色,矩形和X,Y轴平行,如果涂到同一个地方,则覆盖原来的颜色,颜色C<2500,有N<1000个矩...

weixin_30339969的博客 111

usaco Section 3.1 Shaping Regions -- 矩形切割

听说这道题用矩形切割做,于是学习了2004薛矛的oi论文。               我的做法是:弄一个白纸集合,开始里面只有一张白纸(0,0) (A,B)。然后把输入的N个矩形倒序地,每一个都与白纸集合中的所有白纸依次切割。对于输入的矩形rec[i]与每张白纸,用rec[i]去覆盖它。如果有交集,则交集为rec[i]的颜色,把元素个数统计到rec[i]的颜色中,然后把白纸中

. 806

USACO Section 3.1 Shaping Regions (rect1)

Shaping Regions N opaque rectangles (1 <= N <= 1000) of various colors are placed on a white sheet of paper whose size is A wide by B long. The rectangles are put with their sides parallel ...

weixin_30571465的博客 146

usaco6.2.3 Shaping Regions

一 原题 Shaping Regions N opaque rectangles (1 <= N <= 1000) of various colors are placed on a white sheet of paper whose size is A wide by B long. The rectangles are put with their sides paralle

max_kibble的博客 315

[USACO]Shaping Regions

题意:给你一个矩形网格,他的初始网格颜色为1,现在用颜色来覆盖里面的小矩形。问你最后能看到什么颜色且这种颜色的面积有多大。 解题思路:每一次增加一个矩形进来都要判断它和以前的矩形有没有交集,如果有交集则把原先的矩形分为几块。 解题代码: 1 // File Name: kimbits.c 2 // Author: darkdream 3 // Created Time: 2...

weixin_30817749的博客 151

usaco-3.1-PROB Shaping Regions-漂浮法

漂浮法,顾名思义,就是一块块的往上飘。 以逆序来进行放置,即n to 1。逆序的好处在于放置一个矩形后,俯视看到的就是最终俯视该矩形应该看到的。因为挡着它的矩形在之前已经放置好了,所以可直接统计,为递归创造了条件。每放一个矩形,可以想象成将其扔入一密度很大的海水底部,海分成了n层,然后矩形开始向上浮。在上浮过程中若碰撞到其他的矩形则断裂成几个小矩形,继续上浮,直到浮出水面。于是想到用个递归来模拟

青竹梦 1542
上一篇: USACO section 3.1 Humble Numbers(DP)
下一篇: USACO section 3.1 Stamps(dp)
剑不飞
博客等级 码龄15年 86粉丝 505原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址