hdu 2018 多校 第八场

1001 BPM136 母函数然后分子分母分开算,分子二项式展开,分母就是一个组合数

  1 #include
  2 #include
  3 #include
  4 #include
  5 #include
  6 #include
  7 #include
  8 #include
  9 #include
 10 #include
 11 #include<set>
 12 #include
 13 #include
 14 #include
 15 #include
 16 #define pb push_back
 17 #define popb pop_back
 18 #define MID ((l+r)>>1)
 19 #define LSON (k<<1)
 20 #define RSON (k<<1|1)
 21 #define get(a,i) ((a)&(1<<(i-1)))
 22 #define PAU putchar(32)
 23 #define ENT putchar(10)
 24 #define clr(a,b) memset(a,b,sizeof(a))
 25 #define rep(_i,_a,_b) for(int _i=(_a);_i<=(_b);_i++)
 26 #define down(_i,_a,_b) for(int _i=(_a);_i>=(_b);_i--)
 27 #define FOR(_i,_b) for(int _i=1;_i<=(_b);_i++)
 28 #define efo(_i,_a) for(int _i=last[(_a)];_i!=0;_i=e[_i].next)
 29 #define Remax(a,b) if(b>a) a=b;
 30 #define Remin(a,b) if(b 31 #define SZ(x) ((int)(x).size())
 32 #define filein(x) freopen(#x".in","r",stdin)
 33 #define fileout(x) freopen(#x".out","w",stdout)
 34 #define file(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout);
 35 #define mkd(x) freopen(#x".in","w",stdout);
 36 #define setlargestack(x) int _SIZE=x<<20;char *_PPP=(char*)malloc(_SIZE)+_SIZE;__asm__("movl %0, %%esp\n" :: "r"(_PPP));
 37 #define END system("pause")
 38 #define read2(a,b) read(a),read(b)
 39 #define read3(a,b,c) read(a),read(b),read(c)
 40 #define readg(_x1,_y1,_x2,_y2) read(_x1),read(_y1),read(_x2),read(_y2)
 41 using namespace std;
 42 
 43 typedef long long ll;
 44 typedef double DB;
 45 typedef long double LD;
 46 typedef unsigned int  UI;
 47 typedef unsigned long long ULL;
 48 typedef vector<int> VI;
 49 typedef set<int> SI;
 50 typedef set<int , greater<int> > SIG;
 51 typedef map<int, int > MII;
 52 typedef map<int, int, greater<int> > MIIG;
 53 
 54 namespace fastIO{  
 55     #define BUF_SIZE 100000  
 56     #define OUT_SIZE 100000  
 57     //fread->read  
 58     bool IOerror=0;  
 59     inline char nc(){  
 60         static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;  
 61         if (p1==pend){  
 62             p1=buf; pend=buf+fread(buf,1,BUF_SIZE,stdin);  
 63             if (pend==p1){IOerror=1;return -1;}  
 64             //{printf("IO error!\n");system("pause");for (;;);exit(0);}  
 65         }  
 66         return *p1++;  
 67     }  
 68     inline bool blank(char ch){return ch==32||ch==10||ch==13||ch==9;}  
 69     inline bool enter(char ch){return ch==10||ch==13;}
 70     inline void read(int &x){  
 71         bool sign=0; char ch=nc(); x=0;  
 72         for (;blank(ch);ch=nc());  
 73         if (IOerror)return;  
 74         if (ch==45)sign=1,ch=nc();  
 75         for (;ch>=48&&ch<=57;ch=nc())x=x*10+ch-48;  
 76         if (sign)x=-x;  
 77     }  
 78     inline void read(ll &x){  
 79         bool sign=0; char ch=nc(); x=0;  
 80         for (;blank(ch);ch=nc());  
 81         if (IOerror)return;  
 82         if (ch==45)sign=1,ch=nc();  
 83         for (;ch>=48&&ch<=57;ch=nc())x=x*10+ch-48;  
 84         if (sign)x=-x;  
 85     }  
 86     inline void read(double &x){  
 87         bool sign=0; char ch=nc(); x=0;  
 88         for (;blank(ch);ch=nc());  
 89         if (IOerror)return;  
 90         if (ch==45)sign=1,ch=nc();  
 91         for (;ch>=48&&ch<=57;ch=nc())x=x*10+ch-48;  
 92         if (ch==46){  
 93             double tmp=1; ch=nc();  
 94             for (;ch>=48&&ch<=57;ch=nc())tmp/=10.0,x+=tmp*(ch-48);  
 95         }  
 96         if (sign)x=-x;  
 97     }  
 98     inline void read(char *s){  
 99         char ch=nc();  
100         for (;blank(ch);ch=nc());  
101         if (IOerror)return;  
102         for (;!blank(ch)&&!IOerror;ch=nc())*s++=ch;  
103         *s=0;  
104     }  
105     inline void read(char *s,bool f) {
106         char ch=nc();
107         for (;blank(ch);ch=nc());
108         if(IOerror)return;
109         for(;!enter(ch)&&!IOerror;ch=nc())*s++=ch;
110         *s=0;
111     }
112     inline void read(char &c){  
113         for (c=nc();blank(c);c=nc());  
114         if (IOerror){c=-1;return;}  
115     } 
116 #undef OUT_SIZE  
117 #undef BUF_SIZE  
118 }; using namespace fastIO;
119 
120 const int N = 200005;
121 const ll MOD = 998244353;
122 ll inv[N];
123 ll fac[N];
124 ll fac_inv[N];
125 
126 ll C(int n,int m){
127     return fac[n]*fac_inv[m]%MOD*fac_inv[n-m]%MOD;
128 }
129 
130 
131 void init(){
132     inv[0]=fac[0]=inv[1]=fac_inv[0]=1;
133     rep(i,1,N-1) fac[i]=fac[i-1]*i%MOD;
134     rep(i,2,N-1) inv[i]=(MOD-MOD/i)*inv[MOD%i]%MOD;
135     rep(i,1,N-1) fac_inv[i]=fac_inv[i-1]*inv[i]%MOD;
136 }
137 
138 int main() {
139     init();
140     int T;
141     read(T);
142     while(T--) {
143         ll n,m,k;
144         read3(n,m,k);
145         ll ans=0;
146         rep(i,0,m) if(m-1<=k-n*i+m-1){
147             ll tmp=C(m,i)*C(k-n*i+m-1,m-1)%MOD;
148             if(i&1) tmp=-tmp;
149             ans+=tmp;
150             ans%=MOD;
151         }
152         cout<<(ans+MOD)%MOD<<endl;
153     }
154     return 0;
155 }
View Code

 

1004 小甜甜 

 1 #include 
 2 #include 
 3 #include 
 4 #include 
 5 #include 
 6 #include 
 7 #include <set>
 8 #include 
 9 #include <string>
10 #include <string.h>
11 #include 
12 #include 
13 #include 
14 
15 using namespace std;
16 
17 char ans[207][207];
18 
19 int main(){
20     int T;
21     scanf("%d",&T);
22     while (T--) {
23         int n,m;
24         scanf("%d%d",&n,&m);
25         if ((n&1) && (m&1)){
26             for (int i=0;i""))
27                 for (int j=0;j'(');
28         }
29         else if (n&1) {
30             for (int i=0;i"")) 
31                 for (int j=0;j) 
32                     if (j&1) putchar(')');
33                     else putchar('(');
34         }
35         else if (m&1) {
36             for (int i=0;i""))
37                 for (int j=0;j) 
38                     if (i&1) putchar(')');
39                     else putchar('(');
40         }
41         else if ((max(n,m)+min(n,m)/2-1)<=m+n-4){
42             for (int i=0;i'('); puts("");
43             for (int i=1;i1;i++) {
44                 putchar('(');
45                 for (int j=1;j1;j++) 
46                     if ((i+j)&1) putchar('(');
47                     else putchar(')');
48                 puts(")");
49             }
50             for (int i=0;i')'); puts("");
51         }
52         else {
53             int N=min(n,m);
54             int M=max(n,m);
55 
56             for (int i=0;i0][i]='(';
57             for (int i=1;i1;i++) {
58                 for (int j=0;j2;j++) 
59                     if (i&1) ans[i][j]='(';
60                     else ans[i][j]=')';
61                 for (int j=M/2;j) 
62                     if (i&1) ans[i][j]=')';
63                     else ans[i][j]='(';
64             }
65             for (int i=0;i1][i]=')';
66 
67             if (n==N) {
68                 for (int i=0;i"")) 
69                     for (int j=0;j) putchar(ans[i][j]);
70             }
71             else {
72                 for (int i=0;i""))
73                     for (int j=0;j) putchar(ans[j][i]);
74             }
75         }
76     }
77     return 0;
78 }
View Code

 

1005 小甜甜

 1 #include 
 2 #include 
 3 #include 
 4 #include 
 5 #include 
 6 #include 
 7 #include <set>
 8 #include 
 9 #include <string>
10 #include <string.h>
11 #include 
12 #include 
13 #include 
14 
15 using namespace std;
16 
17 char rem[5][5];
18 char s[1000];
19 
20 void work(int k,char c){
21     int x,y;
22     if (k==1) x=y=1;
23     if (k==2) x=1,y=2;
24     if (k==3) x=2,y=1;
25     if (k==4) x=2,y=2;
26 
27     if (c=='C') {
28         char tmp=rem[x][y];
29         rem[x][y]=rem[x+1][y];
30         rem[x+1][y]=rem[x+1][y+1];
31         rem[x+1][y+1]=rem[x][y+1];
32         rem[x][y+1]=tmp;
33     }
34     else {
35         char tmp=rem[x][y];
36         rem[x][y]=rem[x][y+1];
37         rem[x][y+1]=rem[x+1][y+1];
38         rem[x+1][y+1]=rem[x+1][y];
39         rem[x+1][y]=tmp;
40     }
41 }
42 
43 int main(){
44     int T;
45     scanf("%d",&T);
46     while (T--) {
47         int n;
48         scanf("%d",&n);
49         for (int i=1;i<=3;i++) scanf("%s",rem[i]+1);
50 
51         while (n--) {
52             scanf("%s",s);
53             int k=s[0]-'0';
54             work(k,s[1]);
55         }
56 
57         for (int i=1;i<=3;i++) printf("%s\n",rem[i]+1);
58     }
59     return 0;
60 }
View Code

 

1010 小甜甜 (我的锅看错题了,本来贪心就好了被我变成了背包合并)

 1 #include 
 2 #include 
 3 #include 
 4 #include 
 5 #include 
 6 #include 
 7 #include <set>
 8 #include 
 9 #include <string>
10 #include <string.h>
11 #include 
12 #include 
13 #include 
14 
15 using namespace std;
16 
17 const int maxN=1e5+7;
18 
19 typedef pair <int,int> pii;
20 
21 struct query{ 
22     pii p;
23     int id;
24 
25     bool operator < (const query&t) const {
26         return p<t.p;
27     }
28 }q[maxN];
29 
30 int h[maxN];
31 int last[maxN],cnt[maxN],ans[maxN];
32 
33 int sta[maxN],top;
34 
35 void work(){
36     int n,m;
37     scanf("%d%d",&n,&m);
38     for (int i=1;i<=n;i++) scanf("%d",h+i);
39     for (int i=1;i<=m;i++) scanf("%d%d",&q[i].p.first,&q[i].p.second),q[i].id=i;
40     sort(q+1,q+m+1);
41 
42     last[0]=0;
43     for (int i=1;i<=n;i++) {
44         if (h[i]>last[i-1]) {
45             last[i]=h[i];
46             cnt[i]=cnt[i-1]+1;
47         }
48         else {
49             last[i]=last[i-1];
50             cnt[i]=cnt[i-1];
51         }
52     }
53 
54     sta[0]=1e9+7;
55 
56     int j=m;
57     top=0;
58     for (int i=n;i>0;i--) {
59         while (j && q[j].p.first==i) {
60             int mx=last[i-1];
61             ans[q[j].id]=cnt[i-1];
62             if (q[j].p.second>mx) {
63                 ans[q[j].id]++;
64                 mx=q[j].p.second;
65             }
66 
67             int L=0,R=top,mid;
68             while (L<=R) {
69                 mid=(L+R)>>1;
70                 if (sta[mid]<=mx) R=mid-1;
71                 else L=mid+1;
72             }
73 
74             ans[q[j].id]+=R;
75 
76             j--;
77         }
78 
79         while (top>0 && h[i]>=sta[top]) top--;
80         sta[++top]=h[i];
81     }
82 
83     for (int i=1;i<=m;i++) printf("%d\n",ans[i]);
84 }
85 
86 int main(){
87     int T;
88     scanf("%d",&T);
89     while (T--) work();
90     return 0;
91 }
View Code

 

1012 小甜甜 (小甜甜持续超神中)

 1 #include 
 2 #include 
 3 #include 
 4 #include 
 5 #include 
 6 #include 
 7 #include <set>
 8 #include 
 9 #include <string>
10 #include <string.h>
11 #include 
12 #include 
13 #include 
14 
15 using namespace std;
16 
17 const int maxN=5e4+7;
18 
19 long long c[maxN],d[maxN],m[maxN],p[maxN];
20 long long e[maxN],R[maxN],E[maxN];
21 
22 map <long long,long long> rem;
23 map <long long,long long>:: iterator it,it2;
24 
25 void work() {
26     int n;
27     scanf("%d",&n);
28 
29     long long ans=0,sum=0;
30 
31     for (int i=1;i<=n;i++) scanf("%lld%lld%lld%lld",c+i,d+i,m+i,p+i);
32     for (int i=1;i"%lld%lld%lld",e+i,R+i,E+i),sum+=E[i];
33 
34     rem.clear();
35 
36     long long cost=1e9+7;
37     long long cap=0;
38     for (int i=1;i<=n;i++){
39         cost=min(cost,c[i]);
40         rem[cost+m[i]+sum]+=p[i];
41         cap+=p[i];
42 
43         while (!rem.empty() && d[i]) {
44             it=rem.begin();
45             long long k=min(it->second,d[i]);
46             ans+=k*(it->first-sum);
47             d[i]-=k;
48             cap-=k;
49             it->second-=k;
50             if (it->second==0) rem.erase(it);
51         }
52 
53         if (d[i]>0) {
54             puts("-1");
55             return;
56         }
57 
58         if (i==n) break;
59 
60         while (!rem.empty() && cap>e[i]) {
61             it=--rem.end();
62             long long k=min(cap-e[i],it->second); 
63             cap-=k;
64             it->second-=k;
65             if (it->second==0) rem.erase(it);
66         }
67 
68         cost+=R[i];
69         sum-=E[i];
70     }
71     
72     printf("%lld\n",ans);
73 }
74 
75 int main(){
76     int T;
77     scanf("%d",&T);
78     while (T--) work();
79     return 0;
80 }
View Code

 

转载于:https://www.cnblogs.com/MyGirlfriends/p/9507873.html

你可能感兴趣的:(hdu 2018 多校 第八场)