7.14-2014新生暑假個人排位賽01

A.B簽到題,但是都沒有1a。

總結教訓:

1.頭文件忘了寫

   從此27行頭文件時刻準備着。

<span style="font-size:14px;"><span style="font-size:18px;">#include<iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <climits></span></span>

2.總結的規律有問題,就是本質的算法有問題,碰巧舉了兩個相同奇葩規律的例子。

   總結規律的時候至少用三組數據好嗎?!三組!而且不要用極端的例子。

3.scanf讀取的時候lld讀int了。總是喜歡用long long 又對int不離不棄。

   unsigned   int   0~4294967295   (10位)
   int   2147483648~2147483647   (10位)
   long long的最大值:9223372036854775807     (19位)
   long long的最小值:-9223372036854775808     (19位)
   unsigned long long的最大值:18446744073709551615    (20位)




  

---------------------------------接下來是def題解(我的目標是:誰都看得懂!)-----------------------------------------------------------------------------



C、學姐的學弟(話說這些題目真是要把學姐玩壞了)


題意:給個測試組數,給個n,給一堆x,y都是整數的座標作爲圓心,半徑爲1,求總覆蓋面積。

輸入樣例

1
2
1 1
2 1

輸出樣例

5.05482


思路:

看似很雞雜,其實想一想就懂了,鄙視自己的畏懼心理。

1.畫一張直角座標的網格圖出來,對每個矩形分情況討論。有以下三種。

這個時候,小好奇就要問第二幅圖是怎麼算出來的了,算法如下:

S=等邊三角形+2個小扇形。

2.總結一下:

情況一:一個方格內兩條邊被標記(藍藍的就是標記);

情況二:三條;               情況三:四條;

3.對每一個小方格,記錄上下左右4條中一共幾條邊邊被標記,然後就知道這個小方格算面積時用哪種情況的面積。

4.遍歷一遍所有的方格,計算不同情況下面積之和。




代碼我就不貼了,我看別人博客的時候都會很認真的研究別人的代碼,

我這種一個變量名長長長長10個字母的代碼風格就不要誤人子弟了。。。。。


     


D. BLOCKS 

題意:給一幅n*m圖,輸出’#‘構成的矩形個數,要是有一個不是矩形,那就滿盤皆輸。

輸入樣例

6 8
.....#.#
##.....#
##.....#
.......#
#......#
#..#...#
6 8
.....#.#
##.....#
###...##
.......#
##.....#
#..#...#

輸出樣例

There are 5 ships.
So Sad

思路:

同樣看似很瀝撈,其實想一想就懂了,鄙視自己的畏懼心理。

不過這個方法是大神教的,我覺得炒雞好用又容易理解!贊一個~

1.先在圖的周圍加上一圈“..........................................”

2.遍歷整幅圖,對於每個matrix【i】【j】搜他的左上,上,左和他自己,在這四個格子裏面,如果有三個‘#’,就悲劇了.

對每個[i][j]搜與之對應的A,B,C;

3.如果沒有悲劇發生,那就好辦了。找有幾個((自己是“#”)&&(上方||左方是“.”))的塊就行了。

若matrix[i][j]是‘#’,而且B是‘.',或者C是'.',那就矩形個數+1;




E. 數的關係

題意:用關係“<”和“=”將N個數依序排列時有幾種。

輸入樣例

3

輸出樣例

13


思路:

1.首先不能缺掉情況,比如我就少算了四個數字時兩個等號的情況。

2.用動態規劃(dp),從以前的狀態推出現在的狀態,狀態轉移方程是:

for(int i=1;i<=100;i++)
        for(int j=1;j<=100;j++)
        {
            dp[i+1][j]+=dp[i][j]*j;
            dp[i+1][j+1]+=dp[i][j]*(j+1);
        }
/*解釋一下,這裏的i表示有幾個數字,j表示總的<的數目-1。比如i=4,[4][1]=1表示全用等號鏈接有一種方法,[4][2]=14表示有兩個等號其餘用大於或小於的鏈接有14種!!!!我就是這裏算錯了!!!!!!謹記!!!![4][3]=36表示只有一個等號。[4][4]=24表示沒有等號*/

3.毫無疑問,肯定要用大數。貼一個大神師傅給我的大數模板。

#include<cstdio>
#include<iostream>
using namespace std;

const int maxn = 200;
struct bign{
  int len, s[maxn];

  bign() {
    memset(s, 0, sizeof(s));
    len = 1;
  }

  bign(int num) {
    *this = num;
  }

  bign(const char* num) {
    *this = num;
  }

  bign operator = (int num) {
    char s[maxn];
    sprintf(s, "%d", num);
    *this = s;
    return *this;
  }

  bign operator = (const char* num) {
    len = strlen(num);
    for(int i = 0; i < len; i++) s[i] = num[len-i-1] - '0';
    return *this;
  }

  string str() const {
    string res = "";
    for(int i = 0; i < len; i++) res = (char)(s[i] + '0') + res;
    if(res == "") res = "0";
    return res;
  }

  bign operator + (const bign& b) const{
    bign c;
    c.len = 0;
    for(int i = 0, g = 0; g || i < max(len, b.len); i++) {
      int x = g;
      if(i < len) x += s[i];
      if(i < b.len) x += b.s[i];
      c.s[c.len++] = x % 10;
      g = x / 10;
    }
    return c;
  }

  void clean() {
    while(len > 1 && !s[len-1]) len--;
  }

  bign operator * (const bign& b) {
    bign c; c.len = len + b.len;
    for(int i = 0; i < len; i++)
      for(int j = 0; j < b.len; j++)
        c.s[i+j] += s[i] * b.s[j];
    for(int i = 0; i < c.len-1; i++){
      c.s[i+1] += c.s[i] / 10;
      c.s[i] %= 10;
    }
    c.clean();
    return c;
  }

  bign operator - (const bign& b) {
    bign c; c.len = 0;
    for(int i = 0, g = 0; i < len; i++) {
      int x = s[i] - g;
      if(i < b.len) x -= b.s[i];
      if(x >= 0) g = 0;
      else {
        g = 1;
        x += 10;
      }
      c.s[c.len++] = x;
    }
    c.clean();
    return c;
  }

  bool operator < (const bign& b) const{
    if(len != b.len) return len < b.len;
    for(int i = len-1; i >= 0; i--)
      if(s[i] != b.s[i]) return s[i] < b.s[i];
    return false;
  }

  bool operator > (const bign& b) const{
    return b < *this;
  }

  bool operator <= (const bign& b) {
    return !(b > *this);
  }

  bool operator == (const bign& b) {
    return !(b < *this) && !(*this < b);
  }

  bign operator += (const bign& b) {
    *this = *this + b;
    return *this;
  }
};

istream& operator >> (istream &in, bign& x) {
  string s;
  in >> s;
  x = s.c_str();
  return in;
}

ostream& operator << (ostream &out, const bign& x) {
  out << x.str();
  return out;
}

int main() {
  bign a;
  cin >> a;
  a += "123456789123456789000000000";
  cout << a*2 << endl;
  return 0;
}



寫完啦~










發佈了34 篇原創文章 · 獲贊 0 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章