青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

TOPCODER-SRM455

Posted on 2009-12-19 14:07 rikisand 閱讀(577) 評論(0)  編輯 收藏 引用 所屬分類: TopcoderAlgorithm

杯具的比賽~第一題竟然把南和北寫反了- -!第二題沒判斷好復雜度,實際上暴力方法可以的,第三題dp 必然沒寫出來

so----跌成灰色了~~

250pt

Problem Statement

Petya likes spiders. He put a spider in each cell of a rectangular grid. He has studied spiders for many years, so he predicted the behaviour of all of the spiders. At the beginning of each second, every spider will move from its cell to one of the adjacent cells (or off the grid). For each cell, he wrote the direction of its movement to matrix which is represented by a vector <string>, A. The j-th character of i-th element of A will be either 'N', 'S', 'E' or 'W' and it will represent north, south, east and west directions of movement, respectively. If a spider moves outside the grid it falls to the floor. Return the number of free cells after 1 second.

Definition

Class:
SpidersOnTheGrid

Method:
find

Parameters:
vector <string>

Returns:
int

Method signature:
int find(vector <string> A)

(be sure your method is public)

Constraints

-
A will contain between 1 and 50 elements, inclusive.

-
Each element of A will contain between 1 and 50 characters, inclusive.

-
All elements of A will have the same number of characters.

-
Each character will be either 'N', 'E', 'S' or 'W'.

Examples

0)

{"EW","NN"}
Returns: 2

1)

{"EEEEEEEEEEEEEEEEEEEEEEEEEEEEEW"}
Returns: 1

2)

{"EW"}
Returns: 0

3)

{"ESW","ENW"}
Returns: 4

4)

{"E"}
Returns: 1

 

Code Snippet
class SpidersOnTheGrid
{
        public:
        int find(vector <string> A)
        {
            int dr[]={1,0,-1,0};
            int dc[]={0,1,0,-1};
                vector<string > B = A;
                map<char,int> mp;
                mp['S']=0;mp['E']=1;mp['N']=2;mp['W']=3;
                int r = A.size(); int c= A[0].size();
                REP(i,r)REP(j,c){
                    int dir = mp[A[i][j]];
                    if(i+dr[dir]<0||i+dr[dir]>=r||j+dc[dir]<0||j+dc[dir]>=c)continue;
                    B[i+dr[dir]][j+dc[dir]] = 'H';
                }
                int ans = 0;
                REP(i,r)REP(j,c){
                    if(B[i][j]!= 'H')ans++;
                }
                return ans;
        }

 

500pt

這題A的大小只有7個則最多有10^7 種組合來決定下一個元素,也就是說只要枚舉10^7就可以了

Problem Statement

Petya likes sequences. He has an infinite sequence A[] with the following properties:

  • A[0], A[1], ..., A[N-1] are given;
  • A[i]=(A[i-1]+A[i-2]+...+A[i-N])%10 for all i>=N;
Sequence B[] with length M is a substring of A[] if there is such index P that B[0]=A[P], B[1]=A[P+1], ..., B[M-1]=A[P+M-1]. Your task is to find the smallest possible such P. If there is no such index, return -1.
Definition

Class:
EasySequence

Method:
find

Parameters:
vector <int>, vector <int>

Returns:
int

Method signature:
int find(vector <int> A, vector <int> B)

(be sure your method is public)

Constraints

-
A will contain between 1 and 7 elements, inclusive.

-
B will contain between 1 and 50 elements, inclusive.

-
Each element of A will be between 0 and 9, inclusive.

-
Each element of B will be between 0 and 9, inclusive.

Examples

0)

{1,2,3}
{0,7,8,5}
Returns: 5
Starting with 1,2,3 we have:
1+2+3 =  6,  6 % 10 = 6
2+3+6 = 11, 11 % 10 = 1
3+6+1 = 10, 10 % 10 = 0
6+1+0 =  7,  7 % 10 = 7
1+0+7 =  8,  8 % 10 = 8
0+7+8 = 15, 15 % 10 = 5
7+8+5 = 20, 20 % 10 = 0

1,2,3,6,1,0,7,8,5,0
          0,7,8,5      answer = 5

1)

{1,2,8}
{7,4,2,3}
Returns: -1

2)

{1,2,3,4,5}
{4,5}
Returns: 3

3)

{1}
{1,1,1}
Returns: 0
#define REP(i, n) for (int i = 0; i < (n); ++i)  
int C[10000002];
class EasySequence
{
        public:
        int find(vector <int> A, vector <int> B)
        {
            int sum = 0; int n=A.size();
            REP(i,A.size()) sum+= A[i],C[i]=A[i];
            REP(i,10000000){
                C[i+n]=sum%10;
                sum+=(sum%10);
                sum = (sum +10-C[i])%10;
            }
            for(int i=0;i<10000000;i++){
                if(C[i] == B[0]){
                    int k=1;int j=i+1;
                    for(;k<B.size()&&j<10000000&&C[j]==B[k];k++,j++);
                    if(k==B.size())return i;
                }
            }
            return -1;
        }

1000pt

Problem Statement

Petya likes donuts. He tries to find them everywhere. For example if he is given a grid where each cell contains a '0' or '.' he will construct donuts from the cells.

To make the donuts:

  1. Petya first selects a rectangle of cells of width, w, and height, h, where both are at least 3.
  2. Then he removes a rectangular hole of width w-2 and height h-2 centered in the larger rectangle.
  3. For the remaining cells (a closed rectangular ring) to be a valid donut, all of the cells must contain '0' (because donuts are shaped like zeros). Cells in the hole can contain anything since they are not part of the donut.

Here is an example with three overlapping donuts.

..........
.00000000.
.0......0.
.0.000000.
.0.0...00.
.0.0...00.
.0.000000.
.0......0.
.00000000.
..........

The grid in this problem will be pseudo-randomly generated using the following method:
You are given four ints: H (the grid height), W (the grid width), seed and threshold. Let x0=seed and for all i>=0 let xi+1 = (xi * 25173 + 13849) modulo 65536. Process the cells of the matrix in row major order (i.e., first row left to right, second row left to right, etc.). Each time you process a cell, calculate the next xi (starting with x1 for the upper left corner). If it is greater than or equal to threshold, the current cell will contain a '.', otherwise it will contain a '0'.

Return the number of distinct donuts in the figure. Two donuts are considered distinct if they either have different width or height, or if the top left hand corner is in a different location (i.e., overlapping donuts are counted).

Definition

Class:
DonutsOnTheGrid

Method:
calc

Parameters:
int, int, int, int

Returns:
long long

Method signature:
long long calc(int H, int W, int seed, int threshold)

(be sure your method is public)

Notes

-
The random generation of the input is only for keeping the input size small. The author's solution does not depend on any properties of the generator, and would work fast enough for any input of allowed dimensions.

Constraints

-
H will be between 1 and 350, inclusive.

-
W will be between 1 and 350, inclusive.

-
seed will be between 0 and 65535, inclusive.

-
threshold will be between 0 and 65536, inclusive.

Examples

0)

5
5
222
55555
Returns: 4

Here is an example of the grid:

00000
00.0.
.0000
00.00
00000

1)

5
6
121
58000
Returns: 3

Here is the grid and three donuts in it:

00000.   XXX...   XXX...   ..XXX.
0.0000   X.X...   X.X...   ..X.X.
0.000.   X.X...   X.X...   ..XXX.
000.00   XXX...   X.X...   ......
000.00   ......   XXX...   ......

2)

4
5
6
50000
Returns: 1

The grid is:

0.0.0
00000
.00.0
0.000

3)

4
4
1
65536
Returns: 9

Here, the grid is completely filled by 0's. There are 9 possible placements of a donut:

XXX.  XXX.  .XXX  .XXX  ....  ....  XXXX  ....  XXXX
X.X.  X.X.  .X.X  .X.X  XXX.  .XXX  X..X  XXXX  X..X
XXX.  X.X.  .XXX  .X.X  X.X.  .X.X  XXXX  X..X  X..X
....  XXX.  ....  .XXX  XXX.  .XXX  ....  XXXX  XXXX
#define REP(i, n) for (int (i) = 0; i < (n); ++(i)) 
int mp[450][450]; 
int ver[400][450];
class DonutsOnTheGrid
{
        public:
        long long calc(int R, int C, int seed, int threshold)
        {
            int xi = seed ; 
            memset(mp,0,sizeof(mp)); 
            memset(ver,0,sizeof(ver));
            REP(i,R)REP(j,C){
                xi = (xi * 25173 + 13849) % 65536 ;
                mp[i][j] = (xi >= threshold ? 1:0) ;
            }  
            for(int i=R-1;i>=0;i--)
                for(int j=C-1;j>=0;j--){
                    ver[i][j] = ver[i+1][j] + mp[i][j];//記錄列中的累加和
                }
            int64 ans=0;
            for(int i=0;i<R;i++)
                for(int j = i+2;j<R;j++){//求兩行之間的矩形數目
                    int cnt=0;int prev=0;
                    for(int k=0; k<C;k++){//按列從左向右找
                        if(ver[i][k]==ver[i+1][k]&&ver[j][k]==ver[j+1][k]){//如果判斷出此位置不是0則置cnt=0
                            if(ver[i][k]==ver[j+1][k]){//col all 0
                                if(cnt>0){  
                                if(prev==k-1)ans+=(cnt-1);//與之前的豎列組成矩形~
                                else ans+=cnt; 
                                }
                                cnt++;prev=k;
                            } 
                        }
                        else
                            cnt=0;
                    }
                }
                return ans;
        }
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            国产精品视频网| 亚洲精品一区在线观看香蕉| 欧美在线免费观看| 久久免费观看视频| 欧美激情一区二区久久久| 亚洲电影自拍| 亚洲无限乱码一二三四麻| 亚洲视频在线观看免费| 久久精品国产亚洲高清剧情介绍| 亚洲二区视频| 欧美日韩福利| 国产伦精品一区二区| 亚洲国产精品成人精品| 亚洲一区二区在线免费观看视频| 蜜臀久久99精品久久久久久9| 日韩视频―中文字幕| 久久综合五月| 欧美午夜免费电影| 樱桃国产成人精品视频| 欧美亚洲网站| av成人动漫| 欧美xx69| 尤物yw午夜国产精品视频明星| 老司机精品福利视频| 一区二区高清在线观看| 欧美大片在线观看| 亚洲欧美精品在线| 99视频一区二区| 国产一区二区精品久久| 午夜影院日韩| 欧美jizz19性欧美| 亚洲人成网站777色婷婷| 久久亚洲欧美| 久久成人综合网| 国产亚洲毛片在线| 亚洲人成网站777色婷婷| 麻豆成人在线播放| 亚洲精品一区二区三| 亚洲二区免费| 韩日成人在线| 久久在线91| 国产精品一区二区女厕厕| 亚洲国产日本| 欧美日韩在线第一页| 亚洲一区二区在线看| 女人香蕉久久**毛片精品| 午夜一区在线| 国产精品夫妻自拍| 久久精品国产综合| 国产精品成av人在线视午夜片| 欧美91精品| 欧美日韩亚洲一区二| 欧美电影免费观看大全| 欧美国产一区二区在线观看| 亚洲每日在线| 亚洲四色影视在线观看| 国产欧美日韩精品a在线观看| 久久伊人免费视频| 国产日韩视频| 欧美国产国产综合| 亚洲成色www8888| 亚洲欧洲一区二区在线观看| 欧美深夜福利| 久久亚洲午夜电影| 国产一区二区高清| 欧美在线视频全部完| 亚洲国产综合在线看不卡| 一区二区免费在线观看| 正在播放欧美视频| 欧美一区日本一区韩国一区| 亚洲精品乱码久久久久| 你懂的国产精品| 亚洲电影第三页| 99在线精品视频在线观看| 欧美一区高清| 麻豆精品在线播放| 在线观看日韩欧美| 欧美成人四级电影| 亚洲人被黑人高潮完整版| 99热免费精品| 鲁大师影院一区二区三区| 欧美+日本+国产+在线a∨观看| 精品99一区二区| 亚洲一区免费| 一区二区av在线| 欧美视频福利| 欧美一区二视频在线免费观看| 久久婷婷蜜乳一本欲蜜臀| 一色屋精品视频在线观看网站| 久久久久久9999| 欧美亚洲视频在线观看| 国产综合精品| 亚洲欧美不卡| 亚洲网站在线播放| 国产精品自拍小视频| 久久久久国产一区二区| 亚洲欧洲精品一区| 欧美亚洲视频| 亚洲人人精品| 国产视频久久| 欧美极品aⅴ影院| 亚洲国产cao| 亚洲欧美高清| 亚洲国产91| 国产日韩精品视频一区二区三区| 久久免费国产| 免费视频一区二区三区在线观看| 亚洲精品网址在线观看| 国产欧美va欧美不卡在线| 欧美大片专区| 欧美亚洲日本一区| aa级大片欧美| 欧美激情一区在线观看| 欧美一区二区女人| 国产午夜精品久久久| 欧美日本在线| 99视频精品| 欧美福利专区| 久久影音先锋| 欧美一区二区三区免费视频| 亚洲精品一区二区在线| 狠狠88综合久久久久综合网| 欧美日韩精品一区二区在线播放| 久久国产精品一区二区三区| 亚洲视频精选在线| 久久久久久电影| 黑人巨大精品欧美黑白配亚洲| 欧美日韩直播| 欧美精品国产精品| 久久午夜羞羞影院免费观看| 亚洲欧美日韩一区在线| 欧美成人黑人xx视频免费观看| 欧美一区二区三区成人| 亚洲一区二区高清视频| 中国日韩欧美久久久久久久久| 亚洲国产高清一区二区三区| 国产综合亚洲精品一区二| 国产老女人精品毛片久久| 欧美午夜电影网| 欧美日韩美女一区二区| 欧美日本一区二区三区| 欧美久久久久| 欧美日韩的一区二区| 欧美日韩aaaaa| 欧美日韩伦理在线| 欧美色一级片| 国产精品一区二区三区成人| 国产精品视频导航| 国产区亚洲区欧美区| 国产欧美一区二区精品仙草咪| 国产精品一区二区三区四区 | 亚洲黑丝一区二区| 女同一区二区| 亚洲激情欧美激情| 亚洲人成网站色ww在线| 一本大道久久a久久综合婷婷| 亚洲麻豆av| 亚洲视频在线播放| 午夜日韩av| 亚洲精品网站在线播放gif| 亚洲麻豆av| 亚洲欧美成人综合| 久久久www免费人成黑人精品| 99热免费精品| 亚洲一区久久久| 久久精品一区二区国产| 裸体一区二区三区| 欧美日韩午夜剧场| 国产精品亚洲综合久久| 黄色av一区| 亚洲午夜精品| 久久久综合视频| 亚洲欧洲精品一区| 性高湖久久久久久久久| 免费亚洲电影| 国产精品一区二区三区四区 | 欧美午夜不卡在线观看免费| 国产欧美一区二区三区另类精品 | 国产精品入口夜色视频大尺度| 国产九色精品成人porny| 亚洲国产cao| 午夜精品久久久| 亚洲自拍偷拍福利| 鲁大师影院一区二区三区| 最新精品在线| 久久精品国产96久久久香蕉| 欧美剧在线观看| 国产亚洲精久久久久久| 一区二区欧美日韩| 六月婷婷久久| 亚洲调教视频在线观看| 欧美国产日韩免费| 国产午夜精品美女视频明星a级| 日韩一级大片在线| 久久亚洲精品一区| 亚洲免费在线视频| 欧美亚韩一区| 99香蕉国产精品偷在线观看| 久久这里只有| 亚洲欧美偷拍卡通变态|