日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

51nod -1289 . 大鱼吃小鱼(思维)

發布時間:2024/3/24 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 51nod -1289 . 大鱼吃小鱼(思维) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1289?.?大魚吃小魚 題目來源:?Codility 基準時間限制:1?秒 空間限制:65536?KB 分值:?5 有N條魚每條魚的位置及大小均不同,他們沿著X軸游動,有的向左,有的向右。游動的速度是一樣的,兩條魚相遇大魚會吃掉小魚。從左到右給出每條魚的大小和游動的方向(0表示向左,1表示向右)。問足夠長的時間之后,能剩下多少條魚? Input 第1行:1個數N,表示魚的數量(1?<=?N?<=?100000)。 第2?-?N?+?1行:每行兩個數A[i],?B[i],中間用空格分隔,分別表示魚的大小及游動的方向(1?<=?A[i]?<=?10^9,B[i]?=?0?或?1,0表示向左,1表示向右)。 Output 輸出1個數,表示最終剩下的魚的數量。 Input 示例 5 4 0 3 1 2 0 1 0 5 0 Output 示例 2


注意隱含條件是從左至右給出,然后用棧從左至右掃一遍就行了。

#include <iostream> #include <cstdio> #include <cmath> #include <vector> #include <cstring> #include <string> #include <algorithm> #include <string> #include <set> #include <functional> #include <numeric> #include <sstream> #include <stack> #include <map> #include <queue>#define CL(arr, val) memset(arr, val, sizeof(arr))#define ll long long #define inf 0x7f7f7f7f #define lc l,m,rt<<1 #define rc m + 1,r,rt<<1|1 #define pi acos(-1.0)#define L(x) (x) << 1 #define R(x) (x) << 1 | 1 #define MID(l, r) (l + r) >> 1 #define Min(x, y) (x) < (y) ? (x) : (y) #define Max(x, y) (x) < (y) ? (y) : (x) #define E(x) (1 << (x)) #define iabs(x) (x) < 0 ? -(x) : (x) #define OUT(x) printf("%I64d\n", x) #define lowbit(x) (x)&(-x) #define Read() freopen("a.txt", "r", stdin) #define Write() freopen("dout.txt", "w", stdout); #define N 100005 using namespace std; int main() {//Read();stack<int>s;int n,a,b,m;scanf("%d",&n);m=n;while(n--){scanf("%d%d",&a,&b);if(b==1) s.push(a);else{while(!s.empty()){if(a>s.top()) {s.pop();m--;}else { m--;break;}}}}printf("%d\n",m);return 0; }


總結

以上是生活随笔為你收集整理的51nod -1289 . 大鱼吃小鱼(思维)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。