HDU-2018多校7th-1011-Swordsman 附杜教fread代码

HDU-6396

 

题意:

   背景是打怪升级的故事,有k个不同属性的初始的能力值,每只怪物也有相同个数的能力值,你只能放倒k个能力值都比怪物大的,每放倒一个怪物,都可以得到相应的k个能力值。

思路:

   根据k个能力值得到k个不同的排序,设立k个不同的指针从小到大开始移动,对满足被放倒的条件的属性进行标记,当某只monster的所有防御属性都被标记时,更新打怪者的能力值。

  这里的移动操作,可以通过判断cnt是否更新 来结束循环。而每次移动操作都使得指针跑到打怪者能力小于monster的位子。

  自己在练习的时候想的思路有点不周全,我们先对k个能力单独排序,单独给能放倒的怪兽打标记,最后看标记个数是否等于k个。反例是:对某种属性值,你只有打败了A号怪物,才能通过得到的能力值打败其他怪物,而在另一种属性下,A好怪物不能被放倒,但其他怪物能被放倒,这就造成了误判。

代码:

//#include<bits/stdc++.h>
//#include<unordered_map>
//#include<unordered_set>
#include<functional>
#include<algorithm>
//#include<ext/rope>
#include<iomanip>
#include<climits>
#include <iostream>
#include<cstring>
#include<cstdlib>
#include<cstddef>
#include<stdio.h>
#include<memory>
#include<vector>
#include<cctype>
#include<string>
#include<cmath>
#include<queue>
#include<deque>
#include<ctime>
#include<stack>
#include<map>
#include<set>



#define fi first
#define se second
#define pb push_back
#define INF 0x3f3f3f3f
#define pi 3.1415926535898
#define lowbit(a)  (a&(-a))
#define lson l,(l+r)/2,rt<<1
#define rson (l+r)/2+1,r,rt<<1|1
#define Min(a,b,c)  min(a,min(b,c))
#define Max(a,b,c)  max(a,max(b,c))


using namespace std;
//using namespace __gnu_cxx;

typedef long long ll;
typedef pair<int,int> P;
typedef unsigned long long ull;

const ll LLMAX=2e18;
const int MOD=1e9+7;
const int MAXN=1e6+10;


namespace IO{ 
    #define BUF_SIZE 100000 
    #define OUT_SIZE 100000 
    #define ll long long 
    //fread->read 
 
    bool IOerror=0; 
    inline char nc(){ 
        static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE; 
        if (p1==pend){ 
            p1=buf; pend=buf+fread(buf,1,BUF_SIZE,stdin); 
            if (pend==p1){IOerror=1;return -1;} 
            //{printf("IO error!\n");system("pause");for (;;);exit(0);} 
        } 
        return *p1++; 
    } 
    inline bool blank(char ch){return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';} 
    inline void read(int &x){ 
        bool sign=0; char ch=nc(); x=0; 
        for (;blank(ch);ch=nc()); 
        if (IOerror)return; 
        if (ch=='-')sign=1,ch=nc(); 
        for (;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0'; 
        if (sign)x=-x; 
    } 
    inline void read(ll &x){ 
        bool sign=0; char ch=nc(); x=0; 
        for (;blank(ch);ch=nc()); 
        if (IOerror)return; 
        if (ch=='-')sign=1,ch=nc(); 
        for (;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0'; 
        if (sign)x=-x; 
    } 
    inline void read(double &x){ 
        bool sign=0; char ch=nc(); x=0; 
        for (;blank(ch);ch=nc()); 
        if (IOerror)return; 
        if (ch=='-')sign=1,ch=nc(); 
        for (;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0'; 
        if (ch=='.'){ 
            double tmp=1; ch=nc(); 
            for (;ch>='0'&&ch<='9';ch=nc())tmp/=10.0,x+=tmp*(ch-'0'); 
        } 
        if (sign)x=-x; 
    } 
    inline void read(char *s){ 
        char ch=nc(); 
        for (;blank(ch);ch=nc()); 
        if (IOerror)return; 
        for (;!blank(ch)&&!IOerror;ch=nc())*s++=ch; 
        *s=0; 
    } 
    inline void read(char &c){ 
        for (c=nc();blank(c);c=nc()); 
        if (IOerror){c=-1;return;} 
    } 
    //fwrite->write 
    struct Ostream_fwrite{ 
        char *buf,*p1,*pend; 
        Ostream_fwrite(){buf=new char[BUF_SIZE];p1=buf;pend=buf+BUF_SIZE;} 
        void out(char ch){ 
            if (p1==pend){ 
                fwrite(buf,1,BUF_SIZE,stdout);p1=buf; 
            } 
            *p1++=ch; 
        } 
        void print(int x){ 
            static char s[15],*s1;s1=s; 
            if (!x)*s1++='0';if (x<0)out('-'),x=-x; 
            while(x)*s1++=x%10+'0',x/=10; 
            while(s1--!=s)out(*s1); 
        } 
        void println(int x){ 
            static char s[15],*s1;s1=s; 
            if (!x)*s1++='0';if (x<0)out('-'),x=-x; 
            while(x)*s1++=x%10+'0',x/=10; 
            while(s1--!=s)out(*s1); out('\n'); 
        } 
        void print(ll x){ 
            static char s[25],*s1;s1=s; 
            if (!x)*s1++='0';if (x<0)out('-'),x=-x; 
            while(x)*s1++=x%10+'0',x/=10; 
            while(s1--!=s)out(*s1); 
        } 
        void println(ll x){ 
            static char s[25],*s1;s1=s; 
            if (!x)*s1++='0';if (x<0)out('-'),x=-x; 
            while(x)*s1++=x%10+'0',x/=10; 
            while(s1--!=s)out(*s1); out('\n'); 
        } 
        void print(double x,int y){ 
            static ll mul[]={1,10,100,1000,10000,100000,1000000,10000000,100000000, 
                1000000000,10000000000LL,100000000000LL,1000000000000LL,10000000000000LL, 
                100000000000000LL,1000000000000000LL,10000000000000000LL,100000000000000000LL}; 
            if (x<-1e-12)out('-'),x=-x;x*=mul[y]; 
            ll x1=(ll)floor(x); if (x-floor(x)>=0.5)++x1; 
            ll x2=x1/mul[y],x3=x1-x2*mul[y]; print(x2); 
            if (y>0){out('.'); for (size_t i=1;i<y&&x3*mul[i]<mul[y];out('0'),++i); print(x3);} 
        } 
        void println(double x,int y){print(x,y);out('\n');} 
        void print(char *s){while (*s)out(*s++);} 
        void println(char *s){while (*s)out(*s++);out('\n');} 
        void flush(){if (p1!=buf){fwrite(buf,1,p1-buf,stdout);p1=buf;}} 
        ~Ostream_fwrite(){flush();} 
    }Ostream; 
    inline void print(int x){Ostream.print(x);} 
    inline void println(int x){Ostream.println(x);} 
    inline void print(char x){Ostream.out(x);} 
    inline void println(char x){Ostream.out(x);Ostream.out('\n');} 
    inline void print(ll x){Ostream.print(x);} 
    inline void println(ll x){Ostream.println(x);} 
    inline void print(double x,int y){Ostream.print(x,y);} 
    inline void println(double x,int y){Ostream.println(x,y);} 
    inline void print(char *s){Ostream.print(s);} 
    inline void println(char *s){Ostream.println(s);} 
    inline void println(){Ostream.out('\n');} 
    inline void flush(){Ostream.flush();}
    #undef ll 
    #undef OUT_SIZE 
    #undef BUF_SIZE 
};
using namespace IO;
template<class T>
inline void read(T &DataIn)
{
    DataIn=0;    T Flag=0;   char c=getchar();
    while(!isdigit(c)){ Flag|=c=='-'; c=getchar(); }
    while(isdigit(c)){ DataIn=DataIn*10+c-'0'; c=getchar(); }
    DataIn= Flag? -DataIn: DataIn;
}

template<class T>
inline void write(T DataOut,char EndChar='\n')
{
    T lenth=0,number[30];
    if(DataOut==0){ putchar(48); return; }
    while(DataOut>0){ number[++lenth]=DataOut%10; DataOut/=10;}
    for(int i=lenth;i>=1;i--)    putchar(number[i]+48);
    putchar(EndChar);
}

int a[10],pos[10];
struct node{
    ll hit[10],exp[10],id;
}b[MAXN];

int p[10][MAXN];
inline bool cmp1(int x,int y){
    return b[x].hit[0]<b[y].hit[0];
}

inline bool cmp2(int x,int y){
    return b[x].hit[1]<b[y].hit[1];
}

inline bool cmp3(int x,int y){
    return b[x].hit[2]<b[y].hit[2];
}

inline bool cmp4(int x,int y){
    return b[x].hit[3]<b[y].hit[3];
}

inline bool cmp5(int x,int y){
    return b[x].hit[4]<b[y].hit[4];
}


int vis[MAXN];
int main()
{
    
    int T;  cin>>T;
    while(T--){
        int n,k,cnt=0;
        read(n);read(k);
        //scanf("%d%d",&n,&k);
        for(int i=0;i<k;i++)  read(a[i]);
        for(int i=0;i<n;i++){

            vis[i] = 0;
            b[i].id=i;
            for(int j=0;j<k;j++)
                read(b[i].hit[j]),p[j][i] = i;;
            for(int j=0;j<k;j++)
                read(b[i].exp[j]);

        }
        pos[0] = pos[1] = pos[2] =pos[3] = pos[4] = 0;
        for(int i=0; i<k; i++){
            
            if(i==0) sort(p[0],p[0]+n,cmp1);
            else if(i==1) sort(p[1],p[1]+n,cmp2);
            else if(i==2) sort(p[2],p[2]+n,cmp3);
            else if(i==3) sort(p[3],p[3]+n,cmp4);
            else if(i==4) sort(p[4],p[4]+n,cmp5);
        }

        while(true){
                int c = cnt;
                for(int i=0; i<k; i++){
                    while(pos[i] < n && b[p[i][pos[i]]].hit[i] <= a[i]){
                        int id =  p[i][pos[i]];
                        vis[id]++;
                        if(vis[id] == k){
                            cnt++;
                            for(int j=0; j<k; j++){
                                a[j] += b[id].exp[j];
                            }
                        }
                        pos[i]++;
                    }
                }
                if(cnt==c){
                    break;
                }
        }

        //write(cnt);
        IO::println(cnt);
        for(int i=0;i<k;i++)
            IO::print(a[i]),IO::print(i!=k-1?' ':'\n');

    }
    return 0;
}
FREAD in here

 

posted @ 2018-08-14 13:46  ckxkexing  阅读(285)  评论(0编辑  收藏  举报