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

SRM458

Posted on 2010-01-23 21:35 rikisand 閱讀(239) 評論(0)  編輯 收藏 引用

繼續(xù)補上srm的總結(jié):

250pt

Problem Statement

Desertification (the process of good land turning into desert) is a severe problem on Bob's island. Bob's island is a rectangular grid of cells. You are given a vector <string> island that shows the current state of Bob's island. The j-th character of the i-th element of island is 'D' if cell in row i, column j of the grid is desert and is 'F' if this cell is forest.
The desert spreads each year as follows:

  • If a cell is desert, it remains desert forever.
  • If a cell is forest and it is adjacent to at least one desert cell (in one of the four orthogonal directions), it becomes desert after one year.
  • Otherwise the cell remains forest for another year.
Return the number of desert cells after T years.
Definition

Class:
Desertification

Method:
desertArea

Parameters:
vector <string>, int

Returns:
int

Method signature:
int desertArea(vector <string> island, int T)

(be sure your method is public)

Constraints

-
island will contain between 1 and 10 elements, inclusive.

-
Each element of island will contain between 1 and 10 characters, inclusive.

-
Each character in island will be 'D' or 'F'.

-
Each element of island will contain the same number of characters.

-
T will be between 1 and 1,000,000,000, inclusive.

 

記得當時寫了遍歷,如果一個是沙漠則把周圍的都設(shè)置為沙漠,這樣牽涉到一個問題,循環(huán)到某年時候遇到的可能是剛剛變成沙漠的,因此需要每次用一個Vector<string> 記錄新的。

其實對每一個來計算在其T距離內(nèi)有沒有沙漠即可,復(fù)雜度 O(n^4)不過數(shù)據(jù)很小可以過

Code Snippet
int desertArea(vector <string>  land, int T)
{
         int r= land.size(); int c = land[0].size();
         int cnt=0;
         REP(i,r)REP(j,c)  {
             if(land[i][j] == 'D') {cnt++;continue;}
             bool tag=false;
             REP(x,r){
                 if(tag)break;
                 REP(y,c){
                 if(land[x][y]=='D'&&abs(x-i)+abs(y-j)<=T){
                    tag=true;break;
                 }
                 }
             }
             if(tag)cnt++;
         }
         return cnt;
}

500pt

Problem Statement

John is playing with balls. All of the balls are identical in weight and considered to have a zero radius. All balls are located on the same straight line and can move only along this line. If a ball rolling to the right and a ball rolling to the left at the same speed collide, they do not change speed, but they change direction.
You are given vector <int> x. x[i] is the initial position of the i-th ball. John decides the direction for each ball (right or left) with equal probability. At time 0, he rolls the balls in the chosen directions simultaneously at a speed of one unit per second. Return the expected number of bounces between all balls during T seconds (including those collisions that happen exactly at T seconds).

Definition

Class:
BouncingBalls

Method:
expectedBounces

Parameters:
vector <int>, int

Returns:
double

Method signature:
double expectedBounces(vector <int> x, int T)

(be sure your method is public)

Notes

-
There is no friction. Each ball continues rolling at the same speed forever.

-
Your return value must have an absolute or relative error less than 1e-9.

Constraints

-
x will contain between 1 and 12 elements, inclusive.

-
Each element of x will be between 0 and 100,000,000, inclusive.

-
All elements of x will be distinct.

-
T will be between 1 and 100,000,000, inclusive.

Examples

蠻有意思的題,只需要注意到,兩個球碰撞后立即反向,而且速度不變,可以看做兩個球穿越····然后枚舉所有可能的方向2^n種可能即可~~

Code Snippet
class BouncingBalls
{
        public:
        double expectedBounces(vector <int> x, int T)
        {
            int n = x.size();int ans=0;
            sort(x.begin(),x.end());
            REP(i,(1<<n)){
                int mask=1;
                vector<int> vec(n);
                for(int k=0;k<n;k++,mask<<=1){
                    if(mask&i)vec[k] = x[k] + T;
                    else vec[k] = x[k] - T;
                }
                for(int a=0;a<n;a++)
                    for(int b=a+1;b<n;b++){
                        if(vec[a]>=vec[b])ans++;
                    }
            }
            return double(ans)/(1<<n);
        }

 

500分和250分的基本都會用到一些簡化的思想,化復(fù)雜為簡單,化特殊為一般~

1000pt

Problem Statement

You are given six integers, minx, maxx, miny, maxy, minz and maxz. Return the number of triplets of integers (x,y,z) that satisfy the following three conditions:

  • x is between minx and maxx, inclusive.
  • y is between miny and maxy, inclusive.
  • z is between minz and maxz, inclusive.
  • x * y = z
Definition

Class:
ProductTriplet

Method:
countTriplets

Parameters:
int, int, int, int, int, int

Returns:
long long

Method signature:
long long countTriplets(int minx, int maxx, int miny, int maxy, int minz, int maxz)

(be sure your method is public)

Constraints

-
maxx will be between 1 and 1,000,000,000, inclusive.

-
maxy will be between 1 and 1,000,000,000, inclusive.

-
maxz will be between 1 and 1,000,000,000, inclusive.

-
minx will be between 1 and maxx, inclusive.

-
miny will be between 1 and maxy, inclusive.

-
minz will be between 1 and maxz, inclusive.

 

貼一下tutorial中的解釋,挺明白:

The problem asks about the number of triplets of integers (x, y, z), such that
x1 ≤ x ≤ x2
y1 ≤ y ≤ y2
z1 ≤ z ≤ z2
and x * y = z

Let's look at a special case of the problem. Given a fixed x0. Calculate the number of integer triplets (x0, y, z), such that
y1 ≤ y ≤ y2
z1 ≤ z ≤ z2
and x0 * y = z

The conditions on z will derive the following conditions on y.
z1 ≤ x0 * y ≤ z2
z1/x0 ≤ y ≤ z2/x0
ceil(z1/x0) ≤ y ≤ floor(z2/x0)

Another condition on y is y1 ≤ y ≤ y2. So, max(y1, ceil(z1/x0)) ≤ y ≤ min(y2, floor(z2/x0)) are the only limiting conditions on y and z, because any value of y in this range will give a valid (x0, y, z) triplet.

The number of candidate values to y is: min(y2, floor(z2/x0))-max(y1, ceil(z1/x0))+1, provided that the result of the subtraction is not negative. i.e.: the interval is not empty.

 

然后按照這種思想很容易得到第一種方法:

Code Snippet
int64 cacl(int x,int miny,int maxy,int minz,int maxz){
     minz = max(minz,x*x+1);
     if(minz>maxz)return 0;
     miny = max(miny,(minz+x-1)/x);
     maxy = min(maxy,maxz/x);
     return max(0,maxy-miny+1);
}
class ProductTriplet
{
        public:
        long long countTriplets(int minx, int maxx, int miny, int maxy, int minz, int maxz)
        {
            int64 ans=0;
            for(int64 i=minx;i<=maxx && i*i<maxz ;i++)
                ans+=cacl(i,miny,maxy,minz,maxz);
            for(int64 i=miny;i<=maxy && i*i<maxz ;i++)
                ans+=cacl(i,minx,maxx,minz,maxz);
            for(int64 i=max(minx,miny);i<=min(maxx,maxy) && i*i<=maxz;i++)
                if(i*i>=minz)ans++;
            return ans;
        }

首先計算出x<sqrt(z) 然后y<sqrt(z) 最后x==y

注意cacl 中首先要更新minz至少為x*x+1保證x<y;

關(guān)鍵是想到x*y=z直接枚舉會超時,但是分別枚舉x,y 均在sqrt(z) 之內(nèi)可以完成

其他的方法:

Code Snippet
int64 cacl2(int x1,int x2,int y1,int y2,int z1,int z2){
    int x=x1,y=y1;
    int64 ans=0;
    while(x<=x2 && y<=y2 && x*y<=z2){
        int low = (z1+x-1)/x ;
        int high = z2/x;
        low = max(y,low);
        high = min(y2,high);
        if(high>=low)ans+=(high-low+1);
        x++;
        if(high-low<100)
            swap(x,y),swap(x2,y2);
    }
    return ans;
}
int64 cacl(int x1,int x2,int y1,int y2,int z){
    if(z==0)return 0;
    int x=x1,y=y1;
    int64 ans=0;
    while(x<=x2 && y<=y2 && x*y<=z){
        if(x>y){
            swap(x2,y2);swap(x,y);
        }
        int k = z/x ;
        int low = max(1,y);
        int high = min(y2,k);
        if(high>=low)ans+=(high-low+1);
        x++;
    }
    return ans;
}  
class ProductTriplet
{
        public:
        long long countTriplets(int minx, int maxx, int miny, int maxy, int minz, int maxz)
        {
             int64 ans = cacl(minx,maxx,miny,maxy,maxz);
             return ans-cacl(minx,maxx,miny,maxy,minz-1);
            /*return cacl(minx,maxx,miny,maxy,minz,maxz2);*/
        }

 

一種使用cacl函數(shù),計算1 ~maxz的可用對數(shù),然后減去1~(minz-1)的可用對數(shù)即可

計算過程中,枚舉x的值,如果x>y則swap(x,y)其實也是保證枚舉次數(shù)不超過sqrt(z)

另一種方法使用cacl2函數(shù)直接計算結(jié)果,同樣枚舉x的值,不過在得到的y的值小于一定大小

->100 的時候交換x和y,這是基于此時枚舉y值可能更有效率而來的。

在計算ceil(x) 時候有點技巧 low = (z-1+x)/x;

 

 


只有注冊用戶登錄后才能發(fā)表評論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   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>
            国产原创一区二区| 牛牛精品成人免费视频| 国产欧美日韩在线观看| 国产精品入口日韩视频大尺度| 欧美日韩一区在线播放| 欧美日韩一区二区视频在线 | 亚洲人成网在线播放| 亚洲欧美视频在线| 久久国产精品99精品国产| 久久亚洲综合色一区二区三区| 久色婷婷小香蕉久久| 亚洲电影专区| 亚洲午夜精品久久久久久app| 亚洲自拍16p| 久久裸体艺术| 欧美另类亚洲| 国产日产欧美a一级在线| 久久不见久久见免费视频1| 欧美一区日本一区韩国一区| 久久午夜精品一区二区| 欧美日韩大陆在线| 国产婷婷成人久久av免费高清| 亚洲成人在线网站| 亚洲字幕在线观看| 免费观看成人网| 妖精视频成人观看www| 久久成人精品无人区| 欧美精品日本| 一区在线电影| 欧美亚洲在线| 亚洲黄色视屏| 久久av红桃一区二区小说| 欧美久久久久久久久| 精品成人乱色一区二区| 香蕉成人久久| 亚洲国产综合视频在线观看| 亚洲精品在线看| 久久精品一区二区三区四区| 亚洲高清视频一区二区| 欧美与欧洲交xxxx免费观看| 欧美日韩亚洲综合在线| 91久久夜色精品国产九色| 久久亚洲捆绑美女| 亚洲欧洲99久久| 欧美视频日韩视频| 亚洲欧洲一区二区三区久久| 久久精品盗摄| 亚洲专区一区二区三区| 欧美日韩免费在线| 亚洲精品女人| 欧美激情一区| 免费人成精品欧美精品| 亚洲电影免费在线| 免费看黄裸体一级大秀欧美| 国产精品久久久亚洲一区| 久久综合中文字幕| 一区二区在线不卡| 蜜桃久久av| 猫咪成人在线观看| 亚洲国产欧美一区二区三区同亚洲 | 99综合在线| 欧美国产精品久久| 久久久久久久精| 国产一区二区三区精品久久久| 午夜精品福利一区二区三区av| 亚洲伦理在线观看| 欧美日韩日本网| 亚洲五月六月| 亚洲伊人伊色伊影伊综合网| 国产九九精品| 久久精品国产2020观看福利| 久久国产66| 亚洲精品国产精品乱码不99| 亚洲精品永久免费| 国产精品每日更新| 久久视频在线视频| 蜜桃精品久久久久久久免费影院| 亚洲精品国产精品久久清纯直播| 亚洲久久在线| 国产日韩精品一区二区| 你懂的国产精品永久在线| 欧美成人在线影院| 亚洲欧美日韩精品| 久久精品国产免费看久久精品| 亚洲国产经典视频| aa级大片欧美| 黑丝一区二区| 日韩视频免费大全中文字幕| 久久精品欧美日韩| 国产亚洲综合精品| 欧美国产亚洲另类动漫| 欧美日一区二区在线观看| 久久9热精品视频| 免费一级欧美在线大片| 亚洲欧美电影院| 久久―日本道色综合久久| 亚洲一级在线| 美女脱光内衣内裤视频久久网站| 亚洲一区二区三区激情| 久久久水蜜桃| 午夜在线观看欧美| 欧美高清你懂得| 久久se精品一区二区| 欧美激情五月| 久久婷婷成人综合色| 国产精品99免费看| 亚洲国产精品第一区二区| 国产欧美日韩视频在线观看| 亚洲人成网在线播放| 亚洲第一在线视频| 欧美亚洲视频在线观看| 99国产精品久久久久久久成人热| 欧美一区久久| 欧美在现视频| 欧美日韩在线一区二区| 美国十次了思思久久精品导航| 国产精品超碰97尤物18| 最新亚洲一区| 亚洲高清精品中出| 久久久国产视频91| 国产欧美日韩在线| 亚洲视频www| 亚洲狼人精品一区二区三区| 欧美一区二区播放| 久久av红桃一区二区小说| 国产精品久久久久久久久免费| 亚洲精品欧美精品| 亚洲精品国产精品国产自| 老司机精品视频一区二区三区| 欧美福利小视频| 欧美日韩精品在线观看| 牛牛影视久久网| 亚洲国产精品成人| 久久久久久网| 欧美成人免费视频| 亚洲国产天堂久久综合网| 老巨人导航500精品| 麻豆国产va免费精品高清在线| 韩国一区二区在线观看| 久久久久久网址| 欧美高清视频| 亚洲欧洲日本mm| 欧美精品v日韩精品v韩国精品v| 亚洲国产小视频| 亚洲精品视频在线观看网站| 欧美激情视频一区二区三区不卡| 亚洲国产日韩欧美综合久久| 日韩一级网站| 欧美日韩一区二区免费视频| 一本色道久久综合亚洲精品婷婷 | 亚洲激情网站| 女同性一区二区三区人了人一 | 亚洲国产精品电影在线观看| 91久久精品日日躁夜夜躁欧美| 欧美成人精品三级在线观看| 日韩午夜三级在线| 先锋影音网一区二区| 国产一区二区视频在线观看 | 久久精品在线免费观看| 国际精品欧美精品| 看片网站欧美日韩| 亚洲国产精品传媒在线观看 | 亚洲午夜视频在线| 午夜欧美大片免费观看| 国产在线乱码一区二区三区| 久久综合伊人77777麻豆| 日韩一级黄色大片| 久久精品亚洲精品国产欧美kt∨| 影音欧美亚洲| 欧美日本中文| 亚洲欧美亚洲| 亚洲国产精品福利| 欧美在线高清| 日韩一级片网址| 国产综合色在线视频区| 欧美日韩国产综合新一区| 欧美在线啊v一区| 亚洲人体偷拍| 久久激情综合| 久久综合中文| 亚洲欧美视频在线| 国产欧美一区二区精品性| 性18欧美另类| 亚洲国产黄色| 久久成人精品视频| 亚洲乱码国产乱码精品精98午夜| 国产精品日韩精品欧美在线| 久久综合国产精品| 亚洲一区在线播放| 亚洲欧洲日产国产综合网| 久久久亚洲国产天美传媒修理工| 一区二区黄色| 尤物在线精品| 国产日韩精品一区二区| 欧美三区不卡| 欧美大胆人体视频| 久久精品视频免费播放| 亚洲专区在线| 亚洲视频成人| 99亚洲一区二区|