The 19th Zhejiang University Programming Contest Sponsored by TuSimple (Mirror)
http://acm.zju.edu.cn/onlinejudge/showContestProblems.do?contestId=391
A Thanks, TuSimple!
题意:有t组数据,n个男生,m个女生,每个人身高不同,每个人都期望和比自己高或者比自己低的人跳舞,问最多有多少对舞伴
题解:把期待比自己高的男生身高和期待比自己低的男生身高分别存在两个数组a[n],b[n]里,同理对女生也进行这样的操作c[n],d[n],分别对这四个数组进行排序,对于期望比自己的高的男生来说应该找到期望比自己低的女生,这时就可以从a[1]开始找对应的满足条件的d[i](也就是比自己高的女生),同理可以从c[1]开始找对应的满足条件的b[i],(由于排序之后的单调性,所以二者的期望单调性也完全吻合所以正确性也很显然)统计个数即可
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<queue> 5 #include<stack> 6 #include<algorithm> 7 using namespace std; 8 typedef long long ll; 9 ll a[100005],b[100005],q[100005],w[100005],e[100005],r[100005]; 10 int main(){ 11 int t; 12 scanf("%d",&t); 13 while(t--){ 14 int n,m; 15 scanf("%d%d",&n,&m); 16 for(int i=1;i<=n;i++){ 17 scanf("%lld",&a[i]); 18 } 19 for(int i=1;i<=m;i++){ 20 scanf("%lld",&b[i]); 21 } 22 int tot1,tot2,tot3,tot4; 23 tot1=tot2=tot3=tot4=0; 24 for(int i=1;i<=n;i++){ 25 int c; 26 scanf("%d",&c); 27 if(c){ 28 q[++tot1]=a[i]; 29 } 30 else{ 31 w[++tot2]=a[i]; 32 } 33 } 34 for(int i=1;i<=m;i++){ 35 int c; 36 scanf("%d",&c); 37 if(c){ 38 e[++tot3]=b[i]; 39 } 40 else{ 41 r[++tot4]=b[i]; 42 } 43 } 44 sort(q+1,q+1+tot1); 45 sort(w+1,w+1+tot2); 46 sort(e+1,e+1+tot3); 47 sort(r+1,r+1+tot4); 48 int pos1=1; 49 int ans=0; 50 for(int i=1;i<=tot1;i++){ 51 while(pos1<=tot4&&r[pos1]<q[i])pos1++; 52 if(pos1<=tot4){ 53 ans++; 54 pos1++; 55 } 56 else{ 57 break; 58 } 59 } 60 pos1=1; 61 for(int i=1;i<=tot3;i++){ 62 while(pos1<=tot2&&w[pos1]<e[i])pos1++; 63 if(pos1<=tot2){ 64 ans++; 65 pos1++; 66 } 67 else{ 68 break; 69 } 70 } 71 printf("%d ",ans); 72 } 73 return 0; 74 }
题意:给了一堆定义,就是求 e/2+e/4+e/8+e/16.....+0 的值
题解:大数除法+大数加法(模板要用对..板子不对超时一万年..当然也可以使用java,但是我不会)
1 #include<bits/stdc++.h> 2 #define ll long long 3 using namespace std; 4 #define MAXN 9999 5 #define MAXSIZE 1010 6 #define DLEN 4 7 class BigNum{ 8 private: 9 int a[1010]; //可以控制大数的位数 10 int len; 11 public: 12 BigNum(){len=1;memset(a,0,sizeof(a));} //构造函数 13 BigNum(const int); //将一个 int 类型的变量转化成大数 14 BigNum(const char*); //将一个字符串类型的变量转化为大数 15 BigNum(const BigNum &); //拷贝构造函数 16 BigNum &operator=(const BigNum &); //重载赋值运算符,大数之间进行赋值运算 17 friend istream& operator>>(istream&,BigNum&); //重载输入运算符 18 friend ostream& operator<<(ostream&,BigNum&); //重载输出运算符 19 BigNum operator+(const BigNum &)const; //重载加法运算符,两个大数之间的相加运算 20 BigNum operator-(const BigNum &)const; //重载减法运算符,两个大数之间的相减运算 21 BigNum operator*(const BigNum &)const; //重载乘法运算符,两个大数之间的相乘运算 22 BigNum operator/(const int &)const; //重载除法运算符,大数对一个整数进行相除运算 23 BigNum operator^(const int &)const; //大数的 n 次方运算 24 int operator%(const int &)const; //大数对一个类型的变量进行取模运算int 25 bool operator>(const BigNum &T)const; //大数和另一个大数的大小比较 26 bool operator>(const int &t)const; //大数和一个 int 类型的变量的大小比较 27 void print(); //输出大数 28 }; 29 BigNum::BigNum(const int b){ 30 int c, d = b; len=0; 31 memset(a,0,sizeof(a)); 32 while(d>MAXN){ 33 c=d-(d/(MAXN+1))*(MAXN+1); 34 d=d/(MAXN+1); 35 a[len++]=c; 36 } 37 a[len++]=d; 38 } 39 BigNum::BigNum(const BigNum &T):len(T.len){ 40 int i; 41 memset(a,0,sizeof(a)); 42 for(i=0;i<len;i++) 43 a[i]=T.a[i]; 44 } 45 46 BigNum & BigNum::operator=(const BigNum &n){ 47 int i; 48 len=n.len; 49 memset(a,0,sizeof(a)); 50 for(i=0;i<len;i++) 51 a[i]=n.a[i]; 52 return *this; 53 } 54 istream& operator>>(istream &in,BigNum &b){ 55 char ch[MAXSIZE*4]; 56 int i=-1; 57 in>>ch; 58 int L=strlen(ch); 59 int count=0,sum=0; 60 for(i=L-1;i>=0;){ 61 sum=0; 62 int t=1; 63 for(int j=0;j<4&&i>=0;j++,i--,t*=10){ 64 sum+=(ch[i]-'0')*t; 65 } 66 b.a[count]=sum; 67 count++; 68 } 69 b.len=count++; 70 return in; 71 } 72 ostream& operator<<(ostream& out,BigNum& b){ 73 int i; 74 cout<<b.a[b.len-1]; 75 for(i=b.len-2;i>=0;i--){ 76 printf("%04d",b.a[i]); 77 } 78 return out; 79 } 80 BigNum BigNum::operator/(const int &b)const{ 81 BigNum ret; 82 int i,down=0; 83 for(i=len-1;i>=0;i--){ 84 ret.a[i]=(a[i]+down*(MAXN+1))/b; 85 down=a[i]+down*(MAXN+1)-ret.a[i]*b; 86 } 87 ret.len=len; 88 while(ret.a[ret.len-1]==0 && ret.len>1) 89 ret.len--; 90 return ret; 91 } 92 BigNum BigNum::operator+(const BigNum &T)const{ 93 BigNum t(*this); 94 int i,big; 95 big=T.len>len?T.len:len; 96 for(i=0;i<big;i++){ 97 t.a[i]+=T.a[i]; 98 if(t.a[i]>MAXN){ 99 t.a[i+1]++; 100 t.a[i]-=MAXN+1; 101 } 102 } 103 if(t.a[big]!=0) 104 t.len=big+1; 105 else t.len=big; 106 return t; 107 } 108 109 bool BigNum::operator>(const BigNum &T)const{ 110 int ln; 111 if(len>T.len)return true; 112 else if(len==T.len){ 113 ln=len-1; 114 while(a[ln]==T.a[ln]&&ln>=0) 115 ln--; 116 if(ln>=0 && a[ln]>T.a[ln]) 117 return true; 118 else return false; 119 } 120 else return false; 121 } 122 bool BigNum::operator>(const int &t)const{ 123 BigNum b(t); 124 return *this>b; 125 } 126 int main(){ 127 int t; 128 cin>>t; 129 while(t--){ 130 BigNum a; 131 cin>>a; 132 BigNum ans; 133 ans=0; 134 while(a>1){ 135 a=a/2; 136 ans=ans+a; 137 } 138 cout<<ans<<endl; 139 } 140 return 0; 141 }