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

SRM458

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

繼續(xù)補(bǔ)上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.

 

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

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

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

蠻有意思的題,只需要注意到,兩個(gè)球碰撞后立即反向,而且速度不變,可以看做兩個(gè)球穿越····然后枚舉所有可能的方向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分的基本都會(huì)用到一些簡(jiǎn)化的思想,化復(fù)雜為簡(jiǎn)單,化特殊為一般~

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;
        }

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

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

關(guān)鍵是想到x*y=z直接枚舉會(huì)超時(shí),但是分別枚舉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ù),計(jì)算1 ~maxz的可用對(duì)數(shù),然后減去1~(minz-1)的可用對(duì)數(shù)即可

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

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

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

在計(jì)算ceil(x) 時(shí)候有點(diǎn)技巧 low = (z-1+x)/x;

 

 


只有注冊(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>
            欧美一区二区三区成人| 99这里只有久久精品视频| 狠狠v欧美v日韩v亚洲ⅴ| 国产一区二区三区免费在线观看 | 亚洲视频你懂的| 中文精品99久久国产香蕉| 一区二区高清在线| 亚洲与欧洲av电影| 欧美专区日韩专区| 美女免费视频一区| 91久久精品视频| 亚洲理论在线观看| 亚洲欧美久久久| 久久精品视频在线免费观看| 久久香蕉国产线看观看网| 欧美本精品男人aⅴ天堂| 欧美日韩免费网站| 国产欧美一区二区三区在线老狼| 狠狠做深爱婷婷久久综合一区| 在线国产欧美| 9国产精品视频| 小黄鸭精品aⅴ导航网站入口| 久久视频在线看| 亚洲欧洲日韩综合二区| 亚洲专区一区| 久久偷看各类wc女厕嘘嘘偷窃| 欧美另类99xxxxx| 国产欧美一级| 亚洲人妖在线| 欧美影院精品一区| 欧美高清不卡| 亚洲中无吗在线| 另类成人小视频在线| 国产精品www| 亚洲电影免费观看高清完整版| 亚洲性图久久| 欧美成人黑人xx视频免费观看| 亚洲美女免费精品视频在线观看| 欧美一区二区大片| 欧美激情综合| 国内一区二区三区| 亚洲一二三区视频在线观看| 久久天天躁夜夜躁狠狠躁2022 | 日韩网站在线观看| 久久精品99无色码中文字幕| 欧美精品一区在线| 黄色日韩精品| 亚洲欧美日韩网| 亚洲第一区在线观看| 欧美一级视频| 欧美日韩一区二区三区在线观看免 | 久久精品国产一区二区三| 欧美日韩成人综合天天影院| 国产亚洲精品自拍| 亚洲女同在线| 91久久线看在观草草青青| 久久精品视频免费| 国产精品视频免费观看| 99精品视频一区| 欧美freesex交免费视频| 午夜视频一区二区| 欧美日韩在线一区二区三区| 亚洲国产精品成人综合色在线婷婷| 欧美一区二区三区日韩| 99re在线精品| 欧美激情导航| 亚洲高清资源| 久久久亚洲综合| 亚洲制服丝袜在线| 欧美体内she精视频在线观看| 亚洲精品一区二区三区99| 久久综合网络一区二区| 午夜在线精品偷拍| 国产精品欧美经典| 亚洲伊人久久综合| 亚洲最快最全在线视频| 欧美久久视频| 亚洲免费精品| 亚洲国产精品成人va在线观看| 久久米奇亚洲| 狠狠色噜噜狠狠色综合久| 久久av资源网站| 亚洲欧美视频在线观看| 国产精品久久久久免费a∨| 亚洲一级电影| 一二三区精品| 国产精品久久激情| 亚洲欧美日韩综合一区| 一区二区三区成人 | 亚洲天堂偷拍| 日韩天堂av| 欧美视频在线不卡| 亚洲欧美另类在线观看| 这里只有视频精品| 国产精品高潮呻吟久久av黑人| 亚洲图片欧美一区| 夜夜爽av福利精品导航| 欧美视频日韩视频| 亚洲欧美视频一区二区三区| 亚洲一区二区毛片| 国产嫩草一区二区三区在线观看| 午夜视频久久久久久| 亚洲免费视频网站| 国产亚洲精品高潮| 米奇777超碰欧美日韩亚洲| 久久综合影视| 99精品视频一区| 亚洲视频第一页| 国产欧美日本一区视频| 久久只精品国产| 免费在线看一区| 一本一本大道香蕉久在线精品| 一本色道久久综合精品竹菊| 国产精品视频网址| 久久久久综合一区二区三区| 久久综合久久综合这里只有精品| 最新成人av在线| 亚洲精品偷拍| 国产日韩久久| 欧美成人免费在线视频| 欧美日韩高清区| 欧美一级大片在线观看| 久久久美女艺术照精彩视频福利播放| 亚洲高清影视| 一本色道久久综合狠狠躁篇的优点 | 亚洲五月六月| 狠狠综合久久av一区二区小说| 欧美肥婆在线| 欧美日韩中文字幕日韩欧美| 欧美在线一二三四区| 噜噜噜久久亚洲精品国产品小说| 日韩一区二区福利| 亚洲一区免费看| 亚洲国产精品成人精品| 亚洲少妇诱惑| 亚洲国产1区| 亚洲神马久久| 亚洲高清一区二区三区| 亚洲视频在线观看| 亚洲成色999久久网站| 一区二区电影免费在线观看| 国内激情久久| 99成人免费视频| 在线观看成人网| 在线视频亚洲一区| 亚洲国产精品成人va在线观看| 亚洲视频www| 亚洲七七久久综合桃花剧情介绍| 亚洲一区免费| 日韩一级免费| 久久国产主播精品| 亚洲一区精彩视频| 久久先锋资源| 欧美一区二区三区男人的天堂| 免费观看久久久4p| 久久国产夜色精品鲁鲁99| 欧美精品三级日韩久久| 久久亚洲午夜电影| 国产精品卡一卡二| 最新亚洲一区| 在线观看亚洲视频| 亚洲欧美三级伦理| 在线视频日本亚洲性| 美女啪啪无遮挡免费久久网站| 欧美在线观看网站| 欧美午夜性色大片在线观看| 欧美激情黄色片| 国内揄拍国内精品久久| 亚洲一区999| 9久re热视频在线精品| 老司机免费视频一区二区三区| 欧美在线亚洲综合一区| 欧美日韩在线一区| 亚洲国产一区二区三区青草影视| 国产亚洲一本大道中文在线| 中文精品视频一区二区在线观看| 亚洲欧洲日韩综合二区| 久久久亚洲人| 久久午夜视频| 国产午夜精品福利| 亚洲欧美高清| 亚洲综合精品一区二区| 欧美日韩亚洲国产一区| 最新日韩在线| 亚洲精品视频啊美女在线直播| 久久久久久久999| 久久久久久久欧美精品| 国产欧美一区二区色老头| 亚洲一区二区欧美| 亚洲影院污污.| 欧美性事在线| 亚洲视频在线观看视频| 亚洲一区二区在线看| 欧美天堂亚洲电影院在线播放| 亚洲精品免费一区二区三区| 日韩亚洲欧美高清| 欧美日韩视频免费播放| 亚洲精品自在久久| 亚洲无亚洲人成网站77777 | 亚洲激情在线观看视频免费|