HDU 3724 Encoded Barcodes (Trie)

來源:互聯網
上載者:User

標籤:浮點型   namespace   turn   條碼   pre   mat   stack   lib   表示   

題意:給n個字串,給m個詢問,每個詢問給k個條碼。每個條碼由8個小碼組成,每個小碼有相應的寬度,已知一個條碼的寬度只有2種,寬的表示1,窄的表示0。並且寬的寬度是窄的寬度的2倍。由於掃描的時候有誤差,每個小碼的寬度為一個浮點型資料,保證每個資料的誤差在5%內。所以一個條碼可以對應一個ASCC碼,表示一個小寫字母。k個條碼表示一個字串s,每個詢問表示給定的m個字串中以s為首碼的字串個數。

析:很容易看起來是Tire樹, 不知道能不能暴過去,我覺得差不多可以,主要是在處理浮點數上,這個很簡單,既然誤差這麼小,那麼我們就可以取最大值和最小值然後除2,小的為0, 大的為1。

代碼如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")#include <cstdio>#include <string>#include <cstdlib>#include <cmath>#include <iostream>#include <cstring>#include <set>#include <queue>#include <algorithm>#include <vector>#include <map>#include <cctype>#include <cmath>#include <stack>#include <sstream>#include <list>#define debug() puts("++++");#define gcd(a, b) __gcd(a, b)#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define freopenr freopen("in.txt", "r", stdin)#define freopenw freopen("out.txt", "w", stdout)using namespace std;typedef long long LL;typedef unsigned long long ULL;typedef pair<int, int> P;const int INF = 0x3f3f3f3f;const double inf = 0x3f3f3f3f3f3f;const double PI = acos(-1.0);const double eps = 1e-8;const int maxn = 30 * 10000 + 10;const int mod = 10;const int dr[] = {-1, 0, 1, 0};const int dc[] = {0, 1, 0, -1};const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};int n, m;const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};inline bool is_in(int r, int c) {    return r > 0 && r <= n && c > 0 && c <= m;}struct Trie{  int ch[maxn][26];  int val[maxn];  int sz;  void init(){    memset(ch[0], 0, sizeof ch[0]);    sz = 1;  }  int idx(char c){ return c - ‘a‘; }  void insert(char *s){    int u = 0;    for(int i = 0; s[i]; ++i){      int c = idx(s[i]);      if(!ch[u][c]){        memset(ch[sz], 0, sizeof ch[sz]);        val[sz] = 0;        ch[u][c] = sz++;      }      u = ch[u][c];      ++val[u];    }  }  int query(char *s){    int u = 0;    for(int i = 0; s[i]; ++i){      int c = idx(s[i]);      if(!ch[u][c])  return 0;      u = ch[u][c];    }    return val[u];  }};char s[50];Trie trie;double a[10];int main(){  while(scanf("%d %d", &n, &m) == 2){    trie.init();    for(int i = 0; i < n; ++i){      scanf("%s", s);      trie.insert(s);    }    LL ans = 0;    while(m--){      int k;      scanf("%d", &k);      for(int i = 0; i < k; ++i){        double mmin = inf, mmax = -1;        for(int j = 0; j < 8; ++j){          scanf("%lf", a+j);          mmin = min(mmin, a[j]);          mmax = max(mmax, a[j]);        }        double ave = (mmin + mmax) / 2.0;        int t = 0;        for(int j = 0; j < 8; ++j)          if(a[j] < ave)  t = t * 2;          else t = t * 2 + 1;        s[i] = t;      }      s[k] = 0;      ans += trie.query(s);    }    printf("%I64d\n", ans);  }  return 0;}

  

HDU 3724 Encoded Barcodes (Trie)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.