hdu6396 /// fread()快速讀入掛
阿新 • • 發佈:2019-02-15
queue 分享圖片 push 模板 技術 empty turn def sizeof
題目大意:
給定n k
給定主角具有的k種屬性
給定n個怪獸具有的k種屬性和打死該怪獸後能得到的k種屬性對應增幅
求主角最多能打死多少怪獸和最終主角的k種屬性
k最大為5 開5個優先隊列貪心
快速讀入模板
#include <bits/stdc++.h> using namespace std; #define reads(n) FastIO::read(n) namespace FastIO { const int SIZE = 1 << 16; char buf[SIZE], obuf[SIZE], str[60]; int bi = SIZE, bn = SIZE, opt;int read(char *s) { while (bn) { for (; bi < bn && buf[bi] <= ‘ ‘; bi++); if (bi < bn) break; bn = fread(buf, 1, SIZE, stdin); bi = 0; } int sn = 0; while (bn) { for (; bi < bn && buf[bi] > ‘‘; bi++) s[sn++] = buf[bi]; if (bi < bn) break; bn = fread(buf, 1, SIZE, stdin); bi = 0; } s[sn] = 0; return sn; } bool read(int& x) { int n = read(str), bf; if (!n) return 0; int i = 0; if (str[i] == ‘-‘) bf = -1, i++; else bf = 1; for (x = 0; i < n; i++) x = x * 10 + str[i] - ‘0‘; if (bf < 0) x = -x; return 1; } }; int main() { int n; reads(n); return 0; }
#include <bits/stdc++.h> using namespace std; #define LL long long #define INF 0x3f3f3f3f #define mem(i,j) memset(i,j,sizeof(i)) const int N=1e5+5; #define reads(n) FastIO::read(n) namespace FastIO { const int SIZE = 1 << 16; char buf[SIZE], obuf[SIZE], str[60]; int bi = SIZE, bn = SIZE, opt; int read(char *s) { while (bn) { for (; bi < bn && buf[bi] <= ‘ ‘; bi++); if (bi < bn) break; bn = fread(buf, 1, SIZE, stdin); bi = 0; } int sn = 0; while (bn) { for (; bi < bn && buf[bi] > ‘ ‘; bi++) s[sn++] = buf[bi]; if (bi < bn) break; bn = fread(buf, 1, SIZE, stdin); bi = 0; } s[sn] = 0; return sn; } bool read(int& x) { int n = read(str), bf; if (!n) return 0; int i = 0; if (str[i] == ‘-‘) bf = -1, i++; else bf = 1; for (x = 0; i < n; i++) x = x * 10 + str[i] - ‘0‘; if (bf < 0) x = -x; return 1; } }; int n,k; int v[6],a[N][11]; struct NODE{ int x,id; bool operator <(const NODE& p)const { return x>p.x; } }; priority_queue<NODE> q[6]; int main() { int t; reads(t); while(t--) { reads(n); reads(k); for(int i=0;i<k;i++) while(!q[i].empty()) q[i].pop(); for(int i=0;i<k;i++) reads(v[i]); for(int i=0;i<n;i++) for(int j=0;j<2*k;j++) reads(a[i][j]); for(int i=0;i<n;i++) q[0].push({a[i][0],i}); int ans=0; while(1) { bool OK=0; for(int i=0;i<k;i++) { while(!q[i].empty()) { NODE t=q[i].top(); if(t.x<=v[i]) { q[i].pop(); if(i==k-1) { ans++; OK=1; for(int j=0;j<k;j++) v[j]+=a[t.id][j+k]; } else { t.x=a[t.id][i+1]; q[i+1].push(t); } } else break; } } if(!OK) break; } printf("%d\n",ans); for(int i=0;i<k;i++) { printf("%d",v[i]); if(i==k-1) printf("\n"); else printf(" "); } } return 0; }View Code
hdu6396 /// fread()快速讀入掛