查看: 1335|回復: 2
打印 上一主題 下一主題

[HOJ] 39 - 餐廳評鑑

[複製鏈接]

該用戶從未簽到

10

主題

32

帖子

163

積分

高一新生

Rank: 2

積分
163

台南一中資訊社新手達陣

跳轉到指定樓層
樓主
發表於 2014-4-23 13:32:18 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式

趕快加入我們來參與討論吧!

您需要 登錄 才可以下載或查看,沒有帳號?加入我們

x
本帖最後由 ForTest 於 2014-4-23 13:46 編輯

題目:http://hoj.twbbs.org/judge/problem/view/39
AC Code:http://ideone.com/yhOc5k

今天我講的主題><
先照題目條件排序 接著做逆序數對
由於測資有點大 可是不想做離散化
所以code了Merge Sort做練習

Submission id:18647 Status:AC
http://hoj.twbbs.org/judge/judge/submission/18647
#include <iostream>
  • //#include <fstream>
  • #include <sstream>
  • #include <cstdio>
  • #include <cstring>
  • #include <string>
  • #include <cmath>
  • #include <algorithm>
  • //#include <map>
  • #include <stack>
  • #include <queue>
  • #include <vector>
  • //#include <deque>
  • #include <functional>
  • #include <ctime>
  • #include <cstdlib>
  • #include <iomanip>

  • using namespace std;
  • typedef long long LL;

  • #define F(a,b) for(int a=0;a<b;++a)

  • const int Max = 200001;

  • LL ans,k,m;;
  • pair<LL,LL> s[Max],tmp[Max];

  • void Count(int L,int M,int R){
  •     int i = L,j = M+1,pos = 0;
  •     while(i<=M && j<=R){
  •         if(s[i].first < s[j].first && s[i].second > s[j].second){
  •             tmp[pos++] = s[j++];
  •             ans += M - i + 1;
  •         }
  •         else tmp[pos++] = s[i++];
  •     }
  •     while(i <= M)tmp[pos++] = s[i++];
  •     while(j <= R)tmp[pos++] = s[j++];
  •     int now = 0;
  •     while(now < pos)s[L++] = tmp[now++];
  • }


  • void Divide(int L,int R){
  •     if(L == R)return;
  •     int M = (L+R)/2;
  •     Divide(L,M);
  •     Divide(M+1,R);
  •     Count(L,M,R);
  • }

  • int main(){
  •     while(~scanf("%lld%lld",&k,&m)){
  •         ans = 0;
  •         F(i,k)scanf("%lld",&s[i].first);
  •         F(i,k)scanf("%lld",&s[i].second);
  •         sort(s,s+k);
  •         Divide(0,(int)k-1);
  •         printf("%lld\n",ans);
  •     }
  • }





  • 點評

    這些標頭純粹是因為我的編譯器不支援<bits/stdc++.h>阿(大誤  發表於 2014-4-26 11:27
    cstring和string擺一起用不安全吧XD  發表於 2014-4-25 23:08

    評分

    參與人數 1金幣 +3 收起 理由
    Sylveon + 3

    查看全部評分

    回復

    使用道具 檢舉

    您需要登錄後才可以回帖 登入 | 加入我們

    本版積分規則

    快速回覆 返回頂部 返回列表