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

SRM458

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

繼續補上srm的總結:

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.

 

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

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

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分的基本都會用到一些簡化的思想,化復雜為簡單,化特殊為一般~

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;

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

其他的方法:

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函數,計算1 ~maxz的可用對數,然后減去1~(minz-1)的可用對數即可

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

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

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

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

 

 


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   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>
            亚洲全部视频| 久久久久久久综合| 亚洲精品麻豆| 91久久精品久久国产性色也91| 久久成人精品无人区| 蜜臀a∨国产成人精品| 亚洲丶国产丶欧美一区二区三区| 亚洲精品一区二| 香蕉精品999视频一区二区| 久久精品色图| 欧美日韩精品一区二区三区| 国产日韩av高清| 亚洲国产精品一区在线观看不卡| 国精品一区二区三区| 日韩一级在线观看| 久久国产综合精品| 99精品99| 六月婷婷一区| 国产精品一区在线观看| 亚洲国产精品欧美一二99| 亚洲电影观看| 欧美日韩一区三区| 91久久在线观看| 日韩一区二区福利| 欧美风情在线观看| 国语自产精品视频在线看一大j8| 亚洲免费观看高清在线观看 | 国产精品精品视频| 亚洲欧洲另类| 国产精品99久久久久久久女警| 欧美制服第一页| 国产精品色午夜在线观看| 一区二区三区日韩精品| 欧美成人午夜剧场免费观看| 亚洲视频一二区| 在线电影一区| 老司机精品福利视频| 亚洲男女毛片无遮挡| 欧美日韩免费视频| 巨乳诱惑日韩免费av| 欧美日韩国产成人| 麻豆精品一区二区综合av| 欧美激情亚洲激情| 亚洲人体一区| 久久黄色级2电影| 国产一区二区丝袜高跟鞋图片| 久久精品99国产精品酒店日本| 欧美成人免费全部观看天天性色| 亚洲国产人成综合网站| 亚洲永久字幕| 国产亚洲精品高潮| 日韩午夜在线| 亚洲精品在线视频观看| 久久不见久久见免费视频1| 一区二区三区视频在线播放| 美女日韩在线中文字幕| 久久成人av少妇免费| 国产精品www色诱视频| 欧美一区二区三区男人的天堂| 亚洲一区二区三区在线观看视频 | 国产精品永久| 一二美女精品欧洲| 国产一区二区在线观看免费| 亚洲视频电影图片偷拍一区| 亚洲破处大片| 欧美成人精品一区| 亚洲高清123| 亚洲日本va午夜在线电影| 久久免费视频一区| 一本色道久久99精品综合| 一区二区三区高清视频在线观看| 亚洲精品久久久久| 亚洲综合电影| 欧美一区成人| 国产精品你懂的| 欧美高清视频免费观看| 亚洲高清网站| 免费视频久久| 午夜在线视频一区二区区别| 久久成人在线| 免费视频久久| 亚洲精品在线视频| 欧美日韩成人精品| 亚洲视频播放| 久久久噜噜噜久久中文字幕色伊伊| 久久婷婷久久| 91久久午夜| 国产一区二区精品久久91| 欧美一区高清| 99综合视频| 国产精品美女久久久浪潮软件| 亚洲一区二区三区高清不卡| 久久精品三级| 亚洲精华国产欧美| 国产精品福利网| 久久精品国产99精品国产亚洲性色| 久久综合久久久久88| 国产精品久久网站| 久久爱另类一区二区小说| 欧美国产视频一区二区| 国产老女人精品毛片久久| 欧美在线观看视频在线| 亚洲高清精品中出| 亚洲女人小视频在线观看| 欧美激情91| 亚洲欧美日韩成人| 亚洲综合精品自拍| 欧美另类视频在线| 亚洲国产aⅴ天堂久久| 亚洲综合清纯丝袜自拍| 激情综合色综合久久| 欧美一区二区三区免费在线看 | 在线精品国产成人综合| 亚洲一区在线直播| 欧美aa在线视频| 在线观看欧美精品| 欧美视频中文字幕在线| 亚洲毛片播放| 久久久综合网| 亚洲一区二区三区在线| 欧美性一二三区| 巨胸喷奶水www久久久免费动漫| 久久久精品国产一区二区三区 | 久久一区欧美| 亚洲欧美乱综合| 99精品免费视频| 欧美激情视频免费观看| 久久精品青青大伊人av| 亚洲午夜久久久久久久久电影网| 在线欧美福利| 国产资源精品在线观看| 国产精品a久久久久| 欧美激情网站在线观看| 久久久久九九视频| 欧美一区1区三区3区公司| 中日韩在线视频| 亚洲剧情一区二区| 亚洲高清一区二| 欧美高清在线观看| 免费在线成人| 老色鬼久久亚洲一区二区| 久久精品成人一区二区三区| 午夜精品一区二区三区电影天堂 | 久久免费精品日本久久中文字幕| 亚洲一区二区综合| 亚洲视频一区二区在线观看| 99国产一区| 亚洲乱码一区二区| 亚洲精品国偷自产在线99热| 亚洲激情六月丁香| 亚洲国产日韩欧美一区二区三区| 激情综合久久| 亚洲黄色性网站| 最新成人av网站| 亚洲精品国产精品久久清纯直播| 亚洲欧洲视频在线| 一本久道久久综合婷婷鲸鱼| 日韩午夜中文字幕| 亚洲视频第一页| 精品电影在线观看| 亚洲高清在线精品| 亚洲精品资源美女情侣酒店| 日韩亚洲成人av在线| 亚洲无限av看| 性久久久久久久久| 久热精品视频在线观看一区| 你懂的成人av| 亚洲精品中文字幕在线| 一区二区欧美视频| 欧美在线免费观看视频| 久久全国免费视频| 欧美精品国产一区| 国产精品入口日韩视频大尺度| 国产欧美日韩免费| 亚洲国产老妈| 亚洲影院免费观看| 久久这里只精品最新地址| 欧美激情精品久久久久| 一区二区欧美激情| 久久精品久久99精品久久| 欧美成人一区在线| 国产精品美腿一区在线看| 伊人久久久大香线蕉综合直播| 亚洲青涩在线| 欧美一级久久| 亚洲二区精品| 午夜亚洲影视| 欧美日韩国产在线播放网站| 国产欧美日韩| 一本色道久久综合亚洲精品不卡 | 亚洲免费在线精品一区| 久久视频一区二区| 99av国产精品欲麻豆| 欧美有码视频| 欧美视频一区二区三区四区 | 欧美成人免费va影院高清| 国产精品麻豆va在线播放| 亚洲狠狠丁香婷婷综合久久久| 午夜国产精品影院在线观看| 欧美激情视频给我|