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

TOPCODER-SRM455

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

杯具的比賽~第一題竟然把南和北寫反了- -!第二題沒(méi)判斷好復(fù)雜度,實(shí)際上暴力方法可以的,第三題dp 必然沒(méi)寫出來(lái)

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個(gè)則最多有10^7 種組合來(lái)決定下一個(gè)元素,也就是說(shuō)只要枚舉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++){//求兩行之間的矩形數(shù)目
                    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;
        }

只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            久久综合色88| 一区二区冒白浆视频| 欧美午夜一区二区| 老司机精品导航| 亚洲深夜福利视频| 欧美另类99xxxxx| 亚洲精品一区二区三区婷婷月| 亚洲国产另类精品专区 | 亚洲欧洲一区二区三区| 久久免费99精品久久久久久| 久久久久久伊人| 国产亚洲综合在线| 久久精品系列| 亚洲大胆美女视频| 久久久久久久综合色一本| 奶水喷射视频一区| 亚洲国产欧美一区二区三区同亚洲 | 亚洲永久免费观看| 国产精品午夜久久| 欧美一级视频一区二区| 久久综合狠狠| av成人福利| 国产酒店精品激情| 免费日本视频一区| 最新日韩精品| 亚洲在线播放| 亚洲性线免费观看视频成熟| 国产在线欧美| 欧美日韩精品免费观看| 午夜宅男欧美| 亚洲成色最大综合在线| 麻豆精品精品国产自在97香蕉| 久久久久国产精品麻豆ai换脸| 亚洲理伦在线| 国产一区二区三区电影在线观看| 国产精品一区二区三区乱码 | 亚洲第一精品在线| 欧美日韩精选| 欧美日韩国产麻豆| 欧美日韩国产综合在线| 欧美日韩在线播放三区四区| 久久精品亚洲乱码伦伦中文| 久久久久久久一区二区三区| 美女精品国产| 午夜一区不卡| 久久久无码精品亚洲日韩按摩| 久久久久国产精品麻豆ai换脸| 久久影音先锋| 性色av一区二区三区在线观看| 欧美在线|欧美| 一区二区三区福利| 亚洲免费在线视频一区 二区| 欧美成人自拍| 久久久久久久一区| 你懂的国产精品| 91久久在线视频| 亚洲视频欧美视频| 亚洲精品在线免费观看视频| 一区二区三区精密机械公司| 在线免费一区三区| 亚洲精品乱码久久久久久蜜桃麻豆| 黄色成人av网站| 国产欧美不卡| 国产精品无码永久免费888| 国产主播一区二区三区| 在线看不卡av| 亚洲视屏一区| 久久久人人人| 亚洲经典自拍| 欧美一区二区在线| 免费日韩视频| 国产精品麻豆欧美日韩ww| 欧美日韩免费观看一区=区三区| 国产精品视频久久| 在线观看视频日韩| 在线播放中文字幕一区| 夜夜夜精品看看| 久久久久成人网| 亚洲人永久免费| 亚洲精品国产无天堂网2021| 亚洲欧美日韩人成在线播放| 欧美一级视频| 欧美日韩情趣电影| 国产一区高清视频| 一本久久综合亚洲鲁鲁五月天| 久久九九热re6这里有精品| 亚洲国产精品一区二区第一页| 亚洲人成精品久久久久| 午夜精品久久久久久 | 一区在线免费| 亚洲大胆女人| 午夜精品网站| 欧美与欧洲交xxxx免费观看| 性欧美1819性猛交| 久久国产视频网| 老牛国产精品一区的观看方式| 99成人在线| 亚洲自拍偷拍一区| 欧美精品免费观看二区| 欧美日韩精品三区| 在线观看日韩专区| 久久国产精品久久久久久久久久| 日韩亚洲欧美中文三级| 亚洲永久视频| 久久久免费av| 国产丝袜美腿一区二区三区| 亚洲高清激情| 亚洲天堂激情| 亚洲国产一区二区a毛片| 久久精品国产成人| 欧美成人精品在线观看| 欧美涩涩视频| 韩国亚洲精品| 久久精品综合一区| 亚洲性视频h| 蜜臀久久99精品久久久画质超高清| 国产在线拍偷自揄拍精品| 亚洲一区二区三区中文字幕| 亚洲精品免费一区二区三区| 欧美成人免费小视频| 亚洲电影一级黄| 欧美+日本+国产+在线a∨观看| 久久久亚洲国产天美传媒修理工| 国产一区二区高清| 久久精品亚洲乱码伦伦中文| 性一交一乱一区二区洋洋av| 国产日韩欧美在线视频观看| 欧美有码视频| 欧美在线国产| 伊人久久大香线蕉综合热线| 另类欧美日韩国产在线| 久久久女女女女999久久| 亚洲电影免费观看高清| 男人天堂欧美日韩| 欧美www在线| 日韩视频一区二区| 亚洲老司机av| 国产精品国产三级国产aⅴ9色| 亚洲电影激情视频网站| 欧美华人在线视频| 午夜精品在线观看| 国产亚洲一区在线| 久久久久久黄| 免费观看不卡av| 亚洲美女视频在线观看| 亚洲精品综合精品自拍| 国产精品激情| 久久成年人视频| 在线视频精品一区| 国产精品女人久久久久久| 欧美一区二区私人影院日本| 久久成人精品视频| 91久久精品久久国产性色也91 | 亚洲久久成人| 一区二区欧美视频| 国产一区二区三区av电影| 久久免费视频观看| 欧美成人黄色小视频| 亚洲一品av免费观看| 亚洲欧美日韩一区| 亚洲国产成人在线视频| 日韩视频一区二区三区在线播放免费观看| 欧美性猛片xxxx免费看久爱| 久久人人爽爽爽人久久久| 欧美a级一区| 午夜精品免费| 老妇喷水一区二区三区| 一区二区国产在线观看| 亚洲欧美日本另类| 亚洲国产精品久久久久秋霞影院| 99在线|亚洲一区二区| 国产亚洲福利社区一区| 亚洲国产精品一区| 国产老肥熟一区二区三区| 欧美国产日韩a欧美在线观看| 欧美丝袜一区二区| 久久尤物视频| 欧美午夜免费电影| 欧美福利专区| 国产精品天美传媒入口| 亚洲高清在线| 欧美高清你懂得| 一区二区三区日韩在线观看| 久久超碰97人人做人人爱| 日韩一区二区免费高清| 亚洲久久一区二区| 曰本成人黄色| 亚洲欧美国产视频| 亚洲精品一区二区三区不| 久久av资源网站| 亚洲一区二区三区精品在线| 美国十次了思思久久精品导航| 欧美一区二区三区免费观看| 欧美激情视频在线播放| 久久综合久色欧美综合狠狠| 国产精品99免费看 | 中日韩高清电影网| 亚洲国产专区校园欧美| 性欧美18~19sex高清播放| 亚洲一区二区三区成人在线视频精品|