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

TOPCODER-SRM455

Posted on 2009-12-19 14:07 rikisand 閱讀(578) 評論(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>
            午夜视频一区在线观看| 亚洲欧美怡红院| 免费在线视频一区| 老司机67194精品线观看| 国模私拍一区二区三区| 久久久久久午夜| 欧美一区二区三区在线看 | 亚洲日本中文字幕| 久久综合给合| 亚洲精品国产品国语在线app| 欧美激情成人在线视频| 欧美国产视频一区二区| 亚洲乱亚洲高清| 在线亚洲精品| 国产一区二区福利| 欧美电影免费观看大全| 欧美高清在线播放| 欧美一区二区成人| 久久久国产成人精品| 亚洲精品日韩欧美| 宅男噜噜噜66一区二区| 精品不卡视频| 亚洲国产另类 国产精品国产免费| 欧美日韩大片| 久久精品免费电影| 欧美成人黑人xx视频免费观看| 夜夜爽99久久国产综合精品女不卡| 亚洲美女精品一区| 国外精品视频| 99国产精品久久久久久久| 国产精品一区久久| 欧美顶级大胆免费视频| 国产精品入口尤物| 亚洲成人自拍视频| 久久久中精品2020中文| 免费欧美在线| 久久狠狠一本精品综合网| 麻豆精品视频在线观看| 久久成人这里只有精品| 欧美激情视频一区二区三区在线播放| 一本色道久久综合亚洲精品按摩| 性欧美18~19sex高清播放| 亚洲精品1区2区| 午夜精品短视频| 一区二区三区三区在线| 久久久久久久综合| 亚洲一区免费观看| 免费不卡中文字幕视频| 久久av资源网站| 国产精品久久久久久久久久免费看| 欧美va亚洲va香蕉在线| 国产午夜精品麻豆| 一区二区三区四区国产| 亚洲精品一区中文| 久久天堂精品| 久久天堂国产精品| 国产一区二区在线免费观看| 亚洲视频一二三| 一个人看的www久久| 欧美成人一区在线| 欧美va亚洲va国产综合| 伊人成人在线视频| 欧美在线关看| 久久久亚洲精品一区二区三区| 国产精品久久久久av| 亚洲日本成人女熟在线观看| 亚洲国产一区在线| 可以免费看不卡的av网站| 久久伊人亚洲| 国内精品写真在线观看| 欧美综合77777色婷婷| 久久精品国内一区二区三区| 国产一区二区按摩在线观看| 午夜精品在线观看| 久久久久网址| 亚洲国产另类久久精品| 麻豆精品一区二区综合av| 欧美激情国产日韩| 亚洲日本在线视频观看| 欧美金8天国| 夜夜爽99久久国产综合精品女不卡| 一本色道久久加勒比精品| 欧美午夜电影完整版| 亚洲在线不卡| 久久精品九九| 最新国产精品拍自在线播放| 欧美日本乱大交xxxxx| 一区二区三区四区蜜桃| 欧美一站二站| 一色屋精品视频免费看| 欧美成人伊人久久综合网| 99热这里只有精品8| 亚洲欧美日韩国产一区二区| 国产一区二区三区视频在线观看| 久久夜精品va视频免费观看| 亚洲国产经典视频| 亚洲一区激情| 狠狠色丁香久久婷婷综合_中| 欧美xxxx在线观看| 亚洲视频碰碰| 免费在线看成人av| 亚洲免费观看在线视频| 国产精品久久久久久久7电影| 欧美一区在线直播| 亚洲国产视频a| 亚洲欧美日韩一区二区在线| 精品成人在线| 欧美丝袜一区二区| 久久香蕉国产线看观看av| 日韩视频在线一区二区三区| 久久免费黄色| 亚洲淫片在线视频| 影音先锋欧美精品| 欧美视频一区二区三区在线观看| 久久国产直播| 一区二区三区日韩欧美精品| 欧美国产精品劲爆| 欧美一区二区在线播放| 亚洲理伦电影| 一区二区亚洲精品| 欧美午夜精彩| 欧美精品一区二区在线观看| 久久成人免费视频| 亚洲永久免费视频| 亚洲欧洲在线一区| 免费欧美日韩国产三级电影| 欧美一区综合| 亚洲免费婷婷| 在线亚洲成人| 日韩午夜高潮| 91久久久在线| 91久久国产自产拍夜夜嗨| 国产在线不卡精品| 国产精品一区免费在线观看| 欧美日韩视频专区在线播放| 欧美成人精品三级在线观看| 久久久国产精品一区| 欧美一区二区三区免费视频| 亚洲无限av看| 99热在线精品观看| 日韩亚洲欧美综合| 亚洲三级毛片| 亚洲日本成人在线观看| 亚洲经典三级| 亚洲三级免费电影| 亚洲精品国产品国语在线app | 国产精品99久久久久久久久久久久| 亚洲国产日韩在线| 在线免费不卡视频| 伊人蜜桃色噜噜激情综合| 黄色在线一区| 影音先锋中文字幕一区| 亚洲电影在线播放| 91久久精品网| 一区二区三欧美| 亚洲婷婷综合久久一本伊一区| 亚洲视频成人| 欧美亚洲一区二区在线| 欧美在线free| 欧美.www| 最新亚洲一区| 一个色综合av| 亚洲欧美国产高清| 欧美在线国产| 免费h精品视频在线播放| 欧美激情久久久| 国产精品久久久久秋霞鲁丝 | 欧美精品日韩www.p站| 欧美日本亚洲视频| 国产精品国产三级国产专播品爱网| 国产精品多人| 狠狠色丁香久久综合频道| 在线播放视频一区| 99在线精品免费视频九九视| 午夜日韩在线观看| 欧美成人精品激情在线观看| 亚洲精品一区二区三区樱花 | 欧美激情一区二区三区成人| 亚洲人成网在线播放| 亚洲香蕉在线观看| 久久久久久久性| 国产精品a久久久久| 国语自产精品视频在线看一大j8| 亚洲精品老司机| 欧美在现视频| 亚洲国产天堂久久综合网| 亚洲性视频网站| 欧美99在线视频观看| 国产精品久久久久999| 亚洲国产精品电影在线观看| 亚洲欧美国产精品专区久久| 欧美激情性爽国产精品17p| 在线亚洲美日韩| 麻豆成人在线| 国产亚洲激情| 亚洲永久精品国产| 亚洲国产精品小视频| 久久av二区| 欧美午夜免费影院| 亚洲麻豆视频|