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

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>
            日韩天堂在线观看| 久久午夜电影网| 久久国产一区二区| 小黄鸭精品aⅴ导航网站入口| 亚洲精品在线二区| 亚洲日本免费电影| 99国产精品国产精品久久 | 欧美亚洲免费高清在线观看| 亚洲永久在线| 午夜宅男久久久| 久久久久久夜| 欧美电影免费观看| 欧美午夜一区| 国产在线高清精品| 亚洲福利视频二区| 国产精品99久久99久久久二8| 亚洲欧美另类中文字幕| 久久精品99国产精品| 麻豆av一区二区三区| 亚洲精品久久久久久下一站| 99re6这里只有精品| 欧美一区二区观看视频| 美国十次了思思久久精品导航| 欧美乱妇高清无乱码| 国产喷白浆一区二区三区| 亚洲国产日韩美| 午夜精品久久久久久久久久久久 | 欧美一区二区三区日韩视频| 久久人人97超碰人人澡爱香蕉| 欧美mv日韩mv国产网站| 亚洲乱码国产乱码精品精98午夜| 亚洲欧美国产精品va在线观看| 免费欧美日韩| 国产视频久久网| 亚洲高清在线视频| 久久国产精品99国产| 99视频日韩| 欧美成人一区在线| 韩国av一区二区三区在线观看| 亚洲视频一区二区在线观看| 欧美高清自拍一区| 欧美在线视频一区二区三区| 欧美色视频一区| 亚洲精品综合精品自拍| 亚洲一区二区三区在线| 亚洲欧美在线免费| 久久经典综合| 亚洲精品一区在线| 久久人人97超碰精品888| 欧美日韩一区自拍| 亚洲欧洲视频| 欧美不卡视频一区| 亚洲欧美日韩国产一区二区三区| 欧美日韩国产页| 一区二区三区国产在线| 亚洲国产视频一区| 美女啪啪无遮挡免费久久网站| 国产精品主播| 欧美在线国产| 亚洲欧美日韩综合国产aⅴ| 国产精品免费一区豆花| 亚洲欧美激情四射在线日| 夜夜嗨av一区二区三区四区| 欧美日韩情趣电影| 在线视频精品一区| 亚洲国产欧美日韩| 欧美日韩1区| 亚洲欧美国产精品va在线观看| 日韩一级片网址| 国产精品女人网站| 欧美一区二区视频网站| 亚洲资源在线观看| 国产曰批免费观看久久久| 久久全球大尺度高清视频| 久久久噜噜噜久久中文字免| 18成人免费观看视频| 亚洲高清免费视频| 欧美片在线播放| 亚洲一区久久久| 亚洲欧美日韩综合| 亚洲丁香婷深爱综合| 亚洲精品一线二线三线无人区| 欧美色图一区二区三区| 午夜精品久久一牛影视| 亚洲一区制服诱惑| 国内精品亚洲| 欧美综合第一页| 91久久精品国产91久久性色tv| 亚洲国产影院| 国产美女一区| 欧美成人一区二区| 欧美三级小说| 欧美 日韩 国产 一区| 欧美国产日韩一二三区| 亚洲一区二区欧美日韩| 欧美在线欧美在线| 亚洲天堂av在线免费| 欧美一区国产在线| 亚洲精品一区二区在线观看| 一区二区三区四区蜜桃| 在线观看欧美亚洲| 亚洲中字在线| 亚洲毛片一区二区| 亚欧成人在线| 亚洲午夜精品视频| 亚洲欧美国产精品桃花| 欧美有码在线视频| 国产欧美一区二区白浆黑人| 欧美大胆成人| 国产模特精品视频久久久久| 亚洲国产日韩一级| 国产视频久久久久久久| 一区二区三区高清视频在线观看| 一区在线免费| 欧美一级二级三级蜜桃| 亚洲午夜在线观看| 免费日韩av| 久久综合电影| 国产午夜精品在线| 99re成人精品视频| 一本色道久久| 欧美顶级少妇做爰| 欧美成人黑人xx视频免费观看| 国产精品久久久久久久久久直播 | 日韩一级大片在线| 久久青草久久| 美女91精品| 精品999日本| 午夜精品影院| 午夜精品一区二区三区电影天堂 | 中文日韩电影网站| 日韩午夜电影av| 久久人人爽人人爽爽久久| 久久精品成人一区二区三区蜜臀 | 亚洲激情影视| 噜噜爱69成人精品| 男女激情久久| 在线观看一区视频| 久久精品综合网| 久久久久久久综合| 国产一区导航| 久久er精品视频| 久久中文欧美| 亚洲大片免费看| 久久婷婷av| 欧美福利一区二区| 亚洲精品中文在线| 欧美性理论片在线观看片免费| 亚洲自拍16p| 久久精品一区中文字幕| 黄色精品在线看| 另类图片国产| 日韩视频一区二区在线观看 | 国产精品丝袜久久久久久app| 亚洲视频综合在线| 久久精品国产99国产精品澳门| 欧美r片在线| 亚洲国产天堂网精品网站| 欧美激情一区二区三区不卡| 亚洲欧洲精品一区二区| 亚洲视频免费看| 国产精品乱人伦中文| 欧美在线视频网站| 欧美激情一区在线观看| 夜夜躁日日躁狠狠久久88av| 国产精品国产成人国产三级| 亚洲女人av| 欧美国产日韩一区二区| 亚洲自拍都市欧美小说| 国内外成人免费激情在线视频网站 | 久久蜜桃精品| 亚洲人成7777| 久久国产精品毛片| 亚洲欧洲另类国产综合| 国产精品日日摸夜夜添夜夜av| 欧美在线观看视频| 91久久久久久久久| 久久九九国产精品| 亚洲美女免费精品视频在线观看| 欧美日韩亚洲一区三区 | 国产欧美一区二区三区在线老狼| 久久激情中文| 亚洲一区二三| 亚洲国产日韩欧美| 久久久久久久国产| 一本色道久久综合亚洲91| 国产亚洲综合性久久久影院| 欧美激情精品久久久六区热门| 久久国产精品一区二区三区| 亚洲美女淫视频| 美女啪啪无遮挡免费久久网站| 中文一区在线| 亚洲精品永久免费| 尤妮丝一区二区裸体视频| 国产精品观看| 欧美黑人在线观看| 久久精品一区二区三区不卡| 亚洲手机视频| 在线视频免费在线观看一区二区| 亚洲高清中文字幕|