1.FZU2272 Frog

传送门:http://acm.fzu.edu.cn/problem.php?pid=2272

题意:鸡兔同笼通解

题解:解一个方程组直接输出就行

代码如下:

  1. #include <map>
  2. #include <set>
  3. #include <cmath>
  4. #include <ctime>
  5. #include <stack>
  6. #include <queue>
  7. #include <cstdio>
  8. #include <cctype>
  9. #include <bitset>
  10. #include <string>
  11. #include <vector>
  12. #include <cstring>
  13. #include <iostream>
  14. #include <algorithm>
  15. #include <functional>
  16. #define fuck(x) cout<<"["<<x<<"]";
  17. #define FIN freopen("input.txt","r",stdin);
  18. #define FOUT freopen("output.txt","w+",stdout);
  19. //#pragma comment(linker, "/STACK:102400000,102400000")
  20. using namespace std;
  21. typedef long long LL;
  22. typedef pair<int, int> PII;
  23. const int maxn = 1e5+;
  24. const int INF = 0x3f3f3f3f;
  25. const int MOD = 1e9+;
  26.  
  27. int main(){
  28. #ifndef ONLINE_JUDGE
  29. FIN
  30. #endif
  31. int T;
  32. scanf("%d",&T);
  33. while(T--){
  34. int n,m;
  35. cin>>n>>m;
  36. cout<<m/-n<<" "<<*n-m/<<endl;
  37. }
  38. }

2.FZU2273

传送门:http://acm.fzu.edu.cn/problem.php?pid=2273

题意:给你两个三角形,让你判断三角形是相交,相离,还是包含

题解:计算几何模板题,先判断三角形A有没有点在三角形B里面,三角形B有没有点在三角形A里面,然后分情况讨论即可

代码如下:

  1. #include<iostream>
  2. #include<cmath>
  3. using namespace std;
  4. struct point{
  5. int x,y;
  6. }s[][];
  7.  
  8. double m(point a,point b,point c) //叉积
  9. {
  10. return ((b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x));
  11. }
  12.  
  13. bool Judge(point u1,point u2,point v1,point v2) //判断两条线段相交情况
  14. {
  15. return (max(u1.x,u2.x)>=min(v1.x,v2.x)&&
  16. max(u1.y,u2.y)>=min(v1.y,v2.y)&&
  17. max(v1.x,v2.x)>=min(u1.x,u2.x)&&
  18. max(v1.y,v2.y)>=min(u1.y,u2.y)&&
  19. m(u1,v1,u2)*m(u1,u2,v2)>=&&
  20. m(v1,u1,v2)*m(v1,v2,u2)>=);
  21. }
  22.  
  23. int line_check(int p,int q) //判断两个三角形是否相交
  24. {
  25. return (Judge(s[p][],s[p][],s[q][],s[q][])||
  26. Judge(s[p][],s[p][],s[q][],s[q][])||
  27. Judge(s[p][],s[p][],s[q][],s[q][])||
  28. Judge(s[p][],s[p][],s[q][],s[q][])||
  29. Judge(s[p][],s[p][],s[q][],s[q][])||
  30. Judge(s[p][],s[p][],s[q][],s[q][])||
  31. Judge(s[p][],s[p][],s[q][],s[q][])||
  32. Judge(s[p][],s[p][],s[q][],s[q][])||
  33. Judge(s[p][],s[p][],s[q][],s[q][]));
  34. }
  35.  
  36. int point_check(int p,int q) // 面积法判断点在三角形内
  37. {
  38. double res=fabs(m(s[q][],s[q][],s[q][]));
  39. int ans=;
  40. for(int i=;i<;i++)
  41. {
  42. double res1=fabs(m(s[q][],s[q][],s[p][i]));
  43. double res2=fabs(m(s[q][],s[q][],s[p][i]));
  44. double res3=fabs(m(s[q][],s[q][],s[p][i]));
  45. if(res1+res2+res3==res)
  46. ans++;
  47. }
  48. return ans;
  49. }
  50.  
  51. int main()
  52. {
  53. int t;
  54. cin>>t;
  55. while(t--)
  56. {
  57. for(int i=;i<;i++)
  58. for(int j=;j<;j++)
  59. cin>>s[i][j].x>>s[i][j].y;
  60. int ans1=point_check(,),ans2=point_check(,);
  61. if(ans1==&&ans2==) //如果两个三角形没有一个点在另一个三角形内
  62. {
  63. int ans=line_check(,);
  64. if(ans==)
  65. cout<<"disjoint"<<endl; // 相离
  66. else
  67. cout<<"intersect"<<endl; //相交
  68. }
  69. else if(ans1==||ans2==)
  70. cout<<"contain"<<endl; //否则包含
  71. else
  72. cout<<"intersect"<<endl; //相交
  73. }
  74. return ;
  75. }

3.FZU2275

传送门:http://acm.fzu.edu.cn/problem.php?pid=2275

题意:Alice有数字A,Bob有数字B,他们两个人可以对数字进行 1.删除最后一个数,2.将整个数字反转这两个操作,Alice想要将她的数字变得和Bob一样,Bob不想Alice的数字变得和她的一样,最后如果Alice变得和Bob一样了,则Alice赢,否则Bob赢,问你谁会赢

题解:1.如果Bob长度比Alice的数字长度长的话,Bob只需要不断反转他的数字即可,Alice不可能赢

   2.如果Bob的数字为0的话,Alice一定赢

   3.如果Bob的数字是Alice的数字的子串或者Bob数字的反转是Alice数字的子串的话,那么Alice一定赢

代码如下:

  1. #include <map>
  2. #include <set>
  3. #include <cmath>
  4. #include <ctime>
  5. #include <stack>
  6. #include <queue>
  7. #include <cstdio>
  8. #include <cctype>
  9. #include <bitset>
  10. #include <string>
  11. #include <vector>
  12. #include <cstring>
  13. #include <iostream>
  14. #include <algorithm>
  15. #include <functional>
  16. #define fuck(x) cout<<"["<<x<<"]";
  17. #define FIN freopen("input.txt","r",stdin);
  18. #define FOUT freopen("output.txt","w+",stdout);
  19. //#pragma comment(linker, "/STACK:102400000,102400000")
  20. using namespace std;
  21. typedef long long LL;
  22. typedef pair<int, int> PII;
  23. const int maxn = 1e5+;
  24. const int INF = 0x3f3f3f3f;
  25. const int MOD = 1e9+;
  26. int Nxt[maxn];
  27. void makeNext(char P[]) {
  28. int m = strlen(P);
  29. Nxt[] = ;
  30. for (int q = , k = ; q < m; ++q) {
  31. while (k > && P[q] != P[k]) k = Nxt[k - ];
  32. if (P[q] == P[k]) k++;
  33. Nxt[q] = k;
  34. }
  35. }
  36. int kmp(char T[], char P[]) {
  37. int n = strlen(T), m = strlen(P);
  38. makeNext(P);
  39. for (int i = , q = ; i < n; ++i) {
  40. while (q > && P[q] != T[i]) q = Nxt[q - ];
  41. if (P[q] == T[i]) q++;
  42. if (q == m) return i - m + ; //Æ¥Åä³É¹¦,·µ»Ø³É¹¦Ê±Ê×λÖÃ
  43. }
  44. return -;//Æ¥Åäʧ°Ü
  45. }
  46.  
  47. int main(){
  48. #ifndef ONLINE_JUDGE
  49. FIN
  50. #endif
  51. char str1[maxn];
  52. char str2[maxn];
  53. char str3[maxn];
  54. int T;
  55. scanf("%d",&T);
  56. while(T--){
  57. cin>>str1>>str2;
  58. int len1=strlen(str1);
  59. int len2=strlen(str2);
  60. for(int i=;i<len2;i++){
  61. str3[len2-i-]=str2[i];
  62. }
  63. if(len2==&&str2[]==''){
  64. cout<<"Alice"<<endl;
  65. continue;
  66. }
  67. str3[len2]='\0';
  68. if(len1<len2){
  69. cout<<"Bob"<<endl;
  70. }else{
  71. int ans1=kmp(str1,str2);
  72. int ans2=kmp(str1,str3);
  73. if(ans1!=-||ans2!=-){
  74. cout<<"Alice"<<endl;
  75. }else cout<<"Bob"<<endl;
  76. }
  77. }
  78. }

4.FZU2277

传送门:http://acm.fzu.edu.cn/problem.php?pid=2277

题意:给你一颗树的结构,有两种操作,1.将给定节点和这个节点的所有子树上的权值 value += x-deep*k ,2.询问这个节点的权值

题解:线段树和的dfs序,线段树维护该区间节点的权值,dfs序修改其子树的权值,具体题解看代码注释

代码如下:

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <iostream>
  4. #include <algorithm>
  5. #define fuck(x) cout<<"["<<x<<"]";
  6. #define FIN freopen("input.txt","r",stdin);
  7. #define FOUT freopen("output.txt","w+",stdout);
  8. #define lson root<<1
  9. #define rson root<<1|1
  10. #pragma comment(linker, "/STACK:102400000,102400000")
  11. using namespace std;
  12. typedef long long LL;
  13. typedef pair<int, int> PII;
  14. const int maxn = 8e5+;
  15. const int INF = 0x3f3f3f3f;
  16. const int mod = 1e9+;
  17. int n,q;
  18. struct node{
  19. int l,r;
  20. LL sum1;//sum1记录需要加上来的数
  21. LL sum2;//sum2记录需要减去的数
  22. }Tree[maxn<<];
  23. int ltid[maxn]; //更新的左区间
  24. int rtid[maxn]; //更新的右区间
  25. int dep[maxn]; //维护每个节点的深度
  26. struct E{
  27. int v,next;
  28. }edge[maxn];
  29. int head[maxn];
  30. int tot,top;
  31. //前向星建图
  32. inline void add(int u,int v){
  33. edge[tot].v=v;
  34. edge[tot].next=head[u];
  35. head[u]=tot++;
  36. }
  37. //dfs序查询子树的点权和
  38. void dfs(int u,int deep){
  39. ltid[u]=++top;
  40. dep[u]=deep;
  41. for(int i=head[u];i!=-;i=edge[i].next){
  42. int v=edge[i].v;
  43. dfs(v,deep+);
  44. }
  45. rtid[u]=top;
  46. //这样从左到右的一段区间了【lrid,rtid】就表示了节点u的子树权值
  47. return;
  48. }
  49. //建树,节点value值初始化为0
  50. void build(int l,int r ,int root){
  51. Tree[root].l=l;
  52. Tree[root].r=r;
  53. Tree[root].sum1=Tree[root].sum2=;
  54. if(l==r) return;
  55. int mid=(l+r)>>;
  56. build(l,mid,lson);
  57. build(mid+,r,rson);
  58. }
  59. void Add(LL &a,LL b){
  60. a+=b;
  61. a%=mod;
  62. }
  63. //更新节点和子树的sum1和sum2
  64. void push_down(int root){
  65. LL a=Tree[root].sum1;
  66. LL b=Tree[root].sum2;
  67. if(a) Add(Tree[lson].sum1,a);
  68. if(a) Add(Tree[rson].sum1,a);
  69. if(b) Add(Tree[lson].sum2,b);
  70. if(b) Add(Tree[rson].sum2,b);
  71. Tree[root].sum1=Tree[root].sum2=;
  72. }
  73.  
  74. void update(int L,int R,LL x,LL k,int root){
  75. int l=Tree[root].l;
  76. int r=Tree[root].r;
  77. int mid=(l+r)/;
  78. if(L<=l&&r<=R){
  79. //到了需要更改的区间
  80. Add(Tree[root].sum1,x); //sum1加上x
  81. Add(Tree[root].sum2,k); //sum2加上k
  82. return;
  83. }
  84. //更新树
  85. push_down(root);
  86. //更新区间
  87. if(L>mid) update(L,R,x,k,rson);
  88. else if(R<=mid) update(L,R,x,k,lson);
  89. else {
  90. update(L,mid,x,k,lson);
  91. update(mid+,R,x,k,rson);
  92. }
  93. }
  94. LL query(int p,int deep,int root){
  95. if(Tree[root].l==Tree[root].r){
  96. //查询值为 ai+=x-k*deep
  97. return ((Tree[root].sum1-Tree[root].sum2*deep%mod)+mod)%mod;
  98. }
  99. push_down(root);
  100. int mid=(Tree[root].l+Tree[root].r)/;
  101. if(p<=mid) return query(p,deep,lson);
  102. return query(p,deep,rson);
  103. }
  104. int main(){
  105. int T;
  106. scanf("%d",&T);
  107. while(T--){
  108. scanf("%d",&n);
  109. memset(head,-,sizeof(head));
  110. tot=;top=;
  111. int u;
  112. for(int i=;i<=n;i++){
  113. scanf("%d",&u);
  114. add(u,i);
  115. }
  116. dfs(,);
  117. build(,n,);
  118. int op,v,x,k;
  119. scanf("%d",&q);
  120. while(q--){
  121. scanf("%d",&op);
  122. if(op==){
  123. scanf("%d%d%d",&v,&x,&k);
  124. //注意 因为会出现负数,所以我们每次减的操作变成+,最后查询的时候再减
  125. //用两个值分别存所需要加的数和所需要减的数,最后查询的时候操作即可
  126. update(ltid[v],rtid[v],(x*1LL+dep[v]*1LL*k%mod)%mod,k,);
  127. }else{
  128. scanf("%d",&v);
  129. //查询时用
  130. printf("%lld\n",query(ltid[v],dep[v],));
  131. }
  132. }
  133. }
  134. return ;
  135. }

5.FZU2278

传送门:http://acm.fzu.edu.cn/problem.php?pid=2278

题意:有n张牌需要你去抽,每次抽牌的概率是一样的,你每过(n-1)!天可以抽一张牌,求抽齐所有牌的数学期望值

题解:如果我有a张卡,那么我抽到第a+1张卡的概率是(n-a)/n,那么我抽到第a+1张卡平均就需要n/(n-a)天,每隔(n-1)!天就可以抽一次牌

那么我们最后推出来公式就是(n-1)!*n(1+1/2+1/3+……1/n),因为数字特别大,我们要用到大数的知识

三种写法:

1.c++的大数模板

2.Java 的Bignumber

3.python直接写 果然py是最强的

代码如下:

  1. #include <map>
  2. #include <set>
  3. #include <cmath>
  4. #include <ctime>
  5. #include <stack>
  6. #include <queue>
  7. #include <cstdio>
  8. #include <cctype>
  9. #include <bitset>
  10. #include <string>
  11. #include <vector>
  12. #include <cstring>
  13. #include <iostream>
  14. #include <algorithm>
  15. #include <functional>
  16. using namespace std;
  17.  
  18. #define MAXN 9999
  19. #define MAXSIZE 10
  20. #define DLEN 4
  21.  
  22. class BigNum
  23. {
  24. private:
  25. int a[]; //可以控制大数的位数
  26. int len; //大数长度
  27. public:
  28. BigNum(){ len = ;memset(a,,sizeof(a)); } //构造函数
  29. BigNum(const int); //将一个int类型的变量转化为大数
  30. BigNum(const char*); //将一个字符串类型的变量转化为大数
  31. BigNum(const BigNum &); //拷贝构造函数
  32. BigNum &operator=(const BigNum &); //重载赋值运算符,大数之间进行赋值运算
  33.  
  34. friend istream& operator>>(istream&, BigNum&); //重载输入运算符
  35. friend ostream& operator<<(ostream&, BigNum&); //重载输出运算符
  36.  
  37. BigNum operator+(const BigNum &) const; //重载加法运算符,两个大数之间的相加运算
  38. BigNum operator-(const BigNum &) const; //重载减法运算符,两个大数之间的相减运算
  39. BigNum operator*(const BigNum &) const; //重载乘法运算符,两个大数之间的相乘运算
  40. BigNum operator/(const int &) const; //重载除法运算符,大数对一个整数进行相除运算
  41.  
  42. BigNum operator^(const int &) const; //大数的n次方运算
  43. int operator%(const int &) const; //大数对一个int类型的变量进行取模运算
  44. bool operator>(const BigNum & T)const; //大数和另一个大数的大小比较
  45. bool operator>(const int & t)const; //大数和一个int类型的变量的大小比较
  46.  
  47. void print(); //输出大数
  48. };
  49. BigNum::BigNum(const int b) //将一个int类型的变量转化为大数
  50. {
  51. int c,d = b;
  52. len = ;
  53. memset(a,,sizeof(a));
  54. while(d > MAXN)
  55. {
  56. c = d - (d / (MAXN + )) * (MAXN + );
  57. d = d / (MAXN + );
  58. a[len++] = c;
  59. }
  60. a[len++] = d;
  61. }
  62. BigNum::BigNum(const char*s) //将一个字符串类型的变量转化为大数
  63. {
  64. int t,k,index,l,i;
  65. memset(a,,sizeof(a));
  66. l=strlen(s);
  67. len=l/DLEN;
  68. if(l%DLEN)
  69. len++;
  70. index=;
  71. for(i=l-;i>=;i-=DLEN)
  72. {
  73. t=;
  74. k=i-DLEN+;
  75. if(k<)
  76. k=;
  77. for(int j=k;j<=i;j++)
  78. t=t*+s[j]-'';
  79. a[index++]=t;
  80. }
  81. }
  82. BigNum::BigNum(const BigNum & T) : len(T.len) //拷贝构造函数
  83. {
  84. int i;
  85. memset(a,,sizeof(a));
  86. for(i = ; i < len ; i++)
  87. a[i] = T.a[i];
  88. }
  89. BigNum & BigNum::operator=(const BigNum & n) //重载赋值运算符,大数之间进行赋值运算
  90. {
  91. int i;
  92. len = n.len;
  93. memset(a,,sizeof(a));
  94. for(i = ; i < len ; i++)
  95. a[i] = n.a[i];
  96. return *this;
  97. }
  98. istream& operator>>(istream & in, BigNum & b) //重载输入运算符
  99. {
  100. char ch[MAXSIZE*];
  101. int i = -;
  102. in>>ch;
  103. int l=strlen(ch);
  104. int count=,sum=;
  105. for(i=l-;i>=;)
  106. {
  107. sum = ;
  108. int t=;
  109. for(int j=;j<&&i>=;j++,i--,t*=)
  110. {
  111. sum+=(ch[i]-'')*t;
  112. }
  113. b.a[count]=sum;
  114. count++;
  115. }
  116. b.len =count++;
  117. return in;
  118.  
  119. }
  120. ostream& operator<<(ostream& out, BigNum& b) //重载输出运算符
  121. {
  122. int i;
  123. cout << b.a[b.len - ];
  124. for(i = b.len - ; i >= ; i--)
  125. {
  126. cout.width(DLEN);
  127. cout.fill('');
  128. cout << b.a[i];
  129. }
  130. return out;
  131. }
  132.  
  133. BigNum BigNum::operator+(const BigNum & T) const //两个大数之间的相加运算
  134. {
  135. BigNum t(*this);
  136. int i,big; //位数
  137. big = T.len > len ? T.len : len;
  138. for(i = ; i < big ; i++)
  139. {
  140. t.a[i] +=T.a[i];
  141. if(t.a[i] > MAXN)
  142. {
  143. t.a[i + ]++;
  144. t.a[i] -=MAXN+;
  145. }
  146. }
  147. if(t.a[big] != )
  148. t.len = big + ;
  149. else
  150. t.len = big;
  151. return t;
  152. }
  153. BigNum BigNum::operator-(const BigNum & T) const //两个大数之间的相减运算
  154. {
  155. int i,j,big;
  156. bool flag;
  157. BigNum t1,t2;
  158. if(*this>T)
  159. {
  160. t1=*this;
  161. t2=T;
  162. flag=;
  163. }
  164. else
  165. {
  166. t1=T;
  167. t2=*this;
  168. flag=;
  169. }
  170. big=t1.len;
  171. for(i = ; i < big ; i++)
  172. {
  173. if(t1.a[i] < t2.a[i])
  174. {
  175. j = i + ;
  176. while(t1.a[j] == )
  177. j++;
  178. t1.a[j--]--;
  179. while(j > i)
  180. t1.a[j--] += MAXN;
  181. t1.a[i] += MAXN + - t2.a[i];
  182. }
  183. else
  184. t1.a[i] -= t2.a[i];
  185. }
  186. t1.len = big;
  187. while(t1.a[len - ] == && t1.len > )
  188. {
  189. t1.len--;
  190. big--;
  191. }
  192. if(flag)
  193. t1.a[big-]=-t1.a[big-];
  194. return t1;
  195. }
  196.  
  197. BigNum BigNum::operator*(const BigNum & T) const //两个大数之间的相乘运算
  198. {
  199. BigNum ret;
  200. int i,j,up;
  201. int temp,temp1;
  202. for(i = ; i < len ; i++)
  203. {
  204. up = ;
  205. for(j = ; j < T.len ; j++)
  206. {
  207. temp = a[i] * T.a[j] + ret.a[i + j] + up;
  208. if(temp > MAXN)
  209. {
  210. temp1 = temp - temp / (MAXN + ) * (MAXN + );
  211. up = temp / (MAXN + );
  212. ret.a[i + j] = temp1;
  213. }
  214. else
  215. {
  216. up = ;
  217. ret.a[i + j] = temp;
  218. }
  219. }
  220. if(up != )
  221. ret.a[i + j] = up;
  222. }
  223. ret.len = i + j;
  224. while(ret.a[ret.len - ] == && ret.len > )
  225. ret.len--;
  226. return ret;
  227. }
  228. BigNum BigNum::operator/(const int & b) const //大数对一个整数进行相除运算
  229. {
  230. BigNum ret;
  231. int i,down = ;
  232. for(i = len - ; i >= ; i--)
  233. {
  234. ret.a[i] = (a[i] + down * (MAXN + )) / b;
  235. down = a[i] + down * (MAXN + ) - ret.a[i] * b;
  236. }
  237. ret.len = len;
  238. while(ret.a[ret.len - ] == && ret.len > )
  239. ret.len--;
  240. return ret;
  241. }
  242. int BigNum::operator %(const int & b) const //大数对一个int类型的变量进行取模运算
  243. {
  244. int i,d=;
  245. for (i = len-; i>=; i--)
  246. {
  247. d = ((d * (MAXN+))% b + a[i])% b;
  248. }
  249. return d;
  250. }
  251. BigNum BigNum::operator^(const int & n) const //大数的n次方运算
  252. {
  253. BigNum t,ret();
  254. int i;
  255. if(n<)
  256. exit(-);
  257. if(n==)
  258. return ;
  259. if(n==)
  260. return *this;
  261. int m=n;
  262. while(m>)
  263. {
  264. t=*this;
  265. for( i=;i<<<=m;i<<=)
  266. {
  267. t=t*t;
  268. }
  269. m-=i;
  270. ret=ret*t;
  271. if(m==)
  272. ret=ret*(*this);
  273. }
  274. return ret;
  275. }
  276. bool BigNum::operator>(const BigNum & T) const //大数和另一个大数的大小比较
  277. {
  278. int ln;
  279. if(len > T.len)
  280. return true;
  281. else if(len == T.len)
  282. {
  283. ln = len - ;
  284. while(a[ln] == T.a[ln] && ln >= )
  285. ln--;
  286. if(ln >= && a[ln] > T.a[ln])
  287. return true;
  288. else
  289. return false;
  290. }
  291. else
  292. return false;
  293. }
  294. bool BigNum::operator >(const int & t) const //大数和一个int类型的变量的大小比较
  295. {
  296. BigNum b(t);
  297. return *this>b;
  298. }
  299.  
  300. void BigNum::print() //输出大数
  301. {
  302. int i;
  303. cout << a[len - ];
  304. for(i = len - ; i >= ; i--)
  305. {
  306. cout.width(DLEN);
  307. cout.fill('');
  308. cout << a[i];
  309. }
  310. }
  311. int main(void)
  312. {
  313. int i,n;
  314. int T;
  315. cin>>T;
  316. while(T--){
  317. BigNum x; //定义大数的对象数组
  318. BigNum ans;
  319. int n;
  320. cin>>n;
  321. x=;
  322. for(int i=;i<=n;i++){
  323. x=x*i;
  324. }
  325. for(int i=;i<=n;i++){
  326. ans=ans+(x/i);
  327. }
  328. ans.print();
  329. cout<<".0"<<endl;
  330. }
  331. }
  1. import java.util.*;
  2. import java.math.*;
  3. public class Main {
  4. public static void main(String[] args) {
  5. int t;
  6. Scanner sc=new Scanner(System.in);
  7. t=sc.nextInt();
  8. for(int cc=0;cc<t;cc++)
  9. {
  10. BigInteger b=BigInteger.valueOf(1);
  11. int n;
  12. n=sc.nextInt();
  13. for(int i=1;i<=n;i++)
  14. {
  15. b=b.multiply(BigInteger.valueOf(i));
  16. }
  17. BigInteger d=BigInteger.valueOf(0);
  18. for(int i=1;i<=n;i++)
  19. {
  20. BigInteger mm=b.divide(BigInteger.valueOf(i));
  21. d=d.add(mm);
  22. }
  23. System.out.println(d+".0");
  24. }
  25. }
  26. }

6.FZU2281

传送门:http://acm.fzu.edu.cn/problem.php?pid=2281

题意:你手上有m元,可以买和卖货物,货物在n天的价格各不相同,求你n天过后最多可以有多少钱

题解:将货物的价格画成一个曲线,那么我们就可以发现,我们需要在货物价格低的时候买,价格高的时候卖,因为有多个波谷和波峰,就需要对每一个波谷和波峰进行买和卖的操作,这题也是大数,需要用到大数模板

代码如下:

  1. #include <map>
  2. #include <set>
  3. #include <cmath>
  4. #include <ctime>
  5. #include <stack>
  6. #include <queue>
  7. #include <cstdio>
  8. #include <cctype>
  9. #include <bitset>
  10. #include <string>
  11. #include <vector>
  12. #include <cstring>
  13. #include <iostream>
  14. #include <algorithm>
  15. #include <functional>
  16. #define fuck(x) cout<<"["<<x<<"]";
  17. #define FIN freopen("input.txt","r",stdin);
  18. #define FOUT freopen("output.txt","w+",stdout);
  19. //#pragma comment(linker, "/STACK:102400000,102400000")
  20. using namespace std;
  21. typedef long long LL;
  22. typedef pair<int, int> PII;
  23. const int maxn = 3e3+;
  24. const int INF = 0x3f3f3f3f;
  25. const int mod = 1e9+;
  26.  
  27. const int MAXL = 6e3+;
  28. const int MAXN = ;
  29. const int DLEN = ;
  30. class Big {
  31. public:
  32. int a[MAXL], len;
  33. Big(const int b = ) {
  34. int c, d = b;
  35. len = ;
  36. memset(a, , sizeof(a));
  37. while(d > MAXN) {
  38. c = d - (d / (MAXN + )) * (MAXN + );
  39. d = d / (MAXN + );
  40. a[len++] = c;
  41. }
  42. a[len++] = d;
  43. }
  44. Big(const char *s) {
  45. int t, k, index, L;
  46. memset(a, , sizeof(a));
  47. L = strlen(s);
  48. len = L / DLEN;
  49. if(L % DLEN) len++;
  50. index = ;
  51. for(int i = L - ; i >= ; i -= DLEN) {
  52. t = ;
  53. k = i - DLEN + ;
  54. if(k < ) k = ;
  55. for(int j = k; j <= i; j++) t = t * + s[j] - '';
  56. a[index++] = t;
  57. }
  58. }
  59. Big operator/(const LL &b)const {
  60. Big ret;
  61. LL down = ;
  62. for(int i = len - ; i >= ; i--) {
  63. ret.a[i] = (a[i] + down * (MAXN + )) / b;
  64. down = a[i] + down * (MAXN + ) - ret.a[i] * b;
  65. }
  66. ret.len = len;
  67. while(ret.a[ret.len - ] == && ret.len > ) ret.len--;
  68. return ret;
  69. }
  70. bool operator>(const Big &T)const {
  71. int ln;
  72. if(len > T.len) return true;
  73. else if(len == T.len) {
  74. ln = len - ;
  75. while(a[ln] == T.a[ln] && ln >= ) ln--;
  76. if(ln >= && a[ln] > T.a[ln]) return true;
  77. else return false;
  78. } else return false;
  79. }
  80. Big operator+(const Big &T)const {
  81. Big t(*this);
  82. int big = T.len > len ? T.len : len;
  83. for(int i = ; i < big; i++) {
  84. t.a[i] += T.a[i];
  85. if(t.a[i] > MAXN) {
  86. t.a[i + ]++;
  87. t.a[i] -= MAXN + ;
  88. }
  89. }
  90. if(t.a[big] != ) t.len = big + ;
  91. else t.len = big;
  92. return t;
  93. }
  94. Big operator-(const Big &T)const {
  95. int big;
  96. bool flag;
  97. Big t1, t2;
  98. if(*this > T) {
  99. t1 = *this;
  100. t2 = T;
  101. flag = ;
  102. } else {
  103. t1 = T; t2 = *this; flag = ;
  104. }
  105. big = t1.len;
  106. for(int i = ; i < big; i++) {
  107. if(t1.a[i] < t2.a[i]) {
  108. int j = i + ;
  109. while(t1.a[j] == ) j++;
  110. t1.a[j--]--;
  111. while(j > i) t1.a[j--] += MAXN;
  112. t1.a[i] += MAXN + - t2.a[i];
  113. } else t1.a[i] -= t2.a[i];
  114. }
  115. t1.len = big;
  116. while(t1.a[t1.len - ] == && t1.len > ) {
  117. t1.len--;
  118. big--;
  119. }
  120. if(flag) t1.a[big - ] = - t1.a[big - ];
  121. return t1;
  122. }
  123. LL operator%(const int &b)const {
  124. LL d = ;
  125. for(int i = len - ; i >= ; i--) d = ((d * (MAXN + )) % b + a[i]) % b;
  126. return d;
  127. }
  128. Big operator*(const Big &T) const {
  129. Big ret;
  130. int i, j, up, temp, temp1;
  131. for(i = ; i < len; i++) {
  132. up = ;
  133. for(j = ; j < T.len; j++) {
  134. temp = a[i] * T.a[j] + ret.a[i + j] + up;
  135. if(temp > MAXN) {
  136. temp1 = temp - temp / (MAXN + ) * (MAXN + );
  137. up = temp / (MAXN + );
  138. ret.a[i + j] = temp1;
  139. } else {
  140. up = ;
  141. ret.a[i + j] = temp;
  142. }
  143. }
  144. if(up != ) ret.a[i + j] = up;
  145. }
  146. ret.len = i + j;
  147. while(ret.a[ret.len - ] == && ret.len > ) ret.len--;
  148. return ret;
  149. }
  150. void print() {
  151. printf("%d", a[len - ]);
  152. for(int i = len - ; i >= ; i--) printf("%04d", a[i]);
  153. }
  154. };
  155. int a[maxn];
  156. int main(){
  157. int T;
  158. int cas=;
  159. scanf("%d",&T);
  160. while(T--){
  161. int n,m;
  162. printf("Case #%d: ",cas++);
  163. scanf("%d%d",&n,&m);
  164. for(int i=;i<=n;i++){
  165. scanf("%d",&a[i]);
  166. }
  167. if(m==){
  168. printf("0\n");
  169. continue;
  170. }
  171. Big ans=m;
  172. int by=n;
  173. for(int i=;i<n;i++){
  174. if(a[i+]>a[i]){
  175. by=i;
  176. break;
  177. }
  178. }
  179. if(by<n){
  180. Big x=ans/a[by],y=ans%a[by];
  181. while(by<n){
  182. int sl=by+;
  183. while(sl<n&&a[sl+]>=a[sl]) sl++;
  184. if(sl==n){
  185. ans=x*a[sl]+y;
  186. break;
  187. }else{
  188. ans=x*a[sl]+y;
  189. by=sl+;
  190. while(by<n&&a[by]>=a[by+]) by++;
  191. if(by<n) x=ans/a[by],y=ans%a[by];
  192. }
  193. }
  194. }
  195.  
  196. LL x=ans%mod;
  197. cout<<x<<endl;
  198. }
  199. }

7.FZU2282

传送门:http://acm.fzu.edu.cn/problem.php?pid=2282

题意:有一个1~n的全排列,你需要对他进行操作,使得至少有k个人的位置在原来的位置,而剩下的人不在本身的位置

题解:错位排列,公式:

代码如下:

  1. #include <map>
  2. #include <set>
  3. #include <cmath>
  4. #include <ctime>
  5. #include <stack>
  6. #include <queue>
  7. #include <cstdio>
  8. #include <cctype>
  9. #include <bitset>
  10. #include <string>
  11. #include <vector>
  12. #include <cstring>
  13. #include <iostream>
  14. #include <algorithm>
  15. #include <functional>
  16. #define fuck(x) cout<<"["<<x<<"]";
  17. #define FIN freopen("input.txt","r",stdin);
  18. #define FOUT freopen("output.txt","w+",stdout);
  19. //#pragma comment(linker, "/STACK:102400000,102400000")
  20. using namespace std;
  21. typedef long long LL;
  22. typedef pair<int, int> PII;
  23. const int maxn = 1e5+;
  24. const int INF = 0x3f3f3f3f;
  25. const int mod = 1e9+;
  26. LL Jc[maxn];
  27. LL c[maxn];
  28. void calJc() //求maxn以内的数的阶乘
  29. {
  30. Jc[] = Jc[] = ;
  31. Jc[]=;
  32. c[]=;
  33. c[]=;
  34. c[]=;
  35. for(LL i = ; i < maxn; i++){
  36. c[i]=(((i-)%mod)*((c[i-]+c[i-])%mod))%mod;
  37. Jc[i] = Jc[i - ] * i % mod;
  38. }
  39. }
  40. //费马小定理求逆元
  41. LL pow(LL a, LL n, LL p) //快速幂 a^n % p
  42. {
  43. LL ans = ;
  44. while(n)
  45. {
  46. if(n & ) ans = ans * a % p;
  47. a = a * a % p;
  48. n >>= ;
  49. }
  50. return ans;
  51. }
  52. LL niYuan(LL a, LL b) //费马小定理求逆元
  53. {
  54. return pow(a, b - , b);
  55. }
  56. LL C(LL a, LL b) //计算C(a, b)
  57. {
  58. return Jc[a] * niYuan(Jc[b], mod) % mod* niYuan(Jc[a - b], mod) % mod;
  59. }
  60. int main(){
  61. calJc();
  62. int T;
  63. scanf("%d",&T);
  64. while(T--){
  65. int n,k;
  66. scanf("%d%d",&n,&k);
  67. LL ans=;
  68. for(int i=;i<k;i++){
  69. ans=((ans%mod)+(C(n,i)*c[n-i])%mod)%mod;
  70. }
  71. printf("%lld\n",(mod+Jc[n]%mod-ans%mod)%mod);
  72. }
  73. }

8.FZU2283

传送门:http://acm.fzu.edu.cn/problem.php?pid=2283

题意:玩 x棋,Kim先手,给你当前场上的局势和Kim的棋子,每个人都走最优步,问谁可以赢

题解:玩过这个游戏的都知道,只要你场上还有足够的空间并且你占据了中心的那个格子,你是一定赢的,如果不知道为什么,多玩几把就行,所以我们只需要数场上的空格和判断中心即可

代码如下:

  1. #include <map>
  2. #include <set>
  3. #include <cmath>
  4. #include <ctime>
  5. #include <stack>
  6. #include <queue>
  7. #include <cstdio>
  8. #include <cctype>
  9. #include <bitset>
  10. #include <string>
  11. #include <vector>
  12. #include <cstring>
  13. #include <iostream>
  14. #include <algorithm>
  15. #include <functional>
  16. #define fuck(x) cout<<"["<<x<<"]";
  17. #define FIN freopen("input.txt","r",stdin);
  18. #define FOUT freopen("output.txt","w+",stdout);
  19. //#pragma comment(linker, "/STACK:102400000,102400000")
  20. using namespace std;
  21. typedef long long LL;
  22. typedef pair<int, int> PII;
  23. const int maxn = 1e5+;
  24. const int INF = 0x3f3f3f3f;
  25. const int MOD = 1e9+;
  26. char mp[][];
  27.  
  28. int main(){
  29. #ifndef ONLINE_JUDGE
  30. FIN
  31. #endif
  32. int T;
  33. cin>>T;
  34. while(T--){
  35. char ch;
  36. int cnt=;
  37. for(int i=;i<;i++){
  38. for(int j=;j<;j++){
  39. cin>>mp[i][j];
  40. if(mp[i][j]=='.') cnt++;
  41. }
  42. }
  43. cin>>ch;
  44. int flag;
  45. if(cnt<=){
  46. if(mp[][]==ch||mp[][]=='.') flag=;
  47. else flag=;
  48. }else flag=;
  49. if(flag) cout<<"Kim win!"<<endl;
  50. else cout<<"Cannot win!"<<endl;
  51. }
  52. }

以后一定好好写线段树嘤嘤嘤

2017福建省赛 FZU2272~2283的更多相关文章

  1. 2017福建省赛 L Tic-Tac-Toe 模拟

    Kim likes to play Tic-Tac-Toe. Given a current state, and now Kim is going to take his next move. Pl ...

  2. 2017福建省赛 FZU 2278 YYS 数学 大数

    Yinyangshi is a famous RPG game on mobile phones. Kim enjoys collecting cards in this game. Suppose ...

  3. 2017 湖南省赛 K Football Training Camp

    2017 湖南省赛 K Football Training Camp 题意: 在一次足球联合训练中一共有\(n\)支队伍相互进行了若干场比赛. 对于每场比赛,赢了的队伍得3分,输了的队伍不得分,如果为 ...

  4. ACM总结——2017区域赛网络赛总结

    从省赛回来至今4周,每周周末都在打网络赛,每次都是划水,总结下自己弱弱的ACM吧!划水水~~ 首先是新疆赛区,基本上都是图论相关的东西,全靠队友,自己翻水水,实力躺了5道. 然后是沈阳赛区,终于有点贡 ...

  5. 2017浙江省赛 A - Cooking Competition ZOJ - 3958

    地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3958 题目: "Miss Kobayashi's Drag ...

  6. 【数论】【原根】【动态规划】【bitset】2017四川省赛 K.2017 Revenge

    题意: 给你n(不超过200w)个数,和一个数r,问你有多少种方案,使得你取出某个子集,能够让它们的乘积 mod 2017等于r. 2017有5这个原根,可以使用离散对数(指标)的思想把乘法转化成加法 ...

  7. hihoCoder 1582 Territorial Dispute 【凸包】(ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1582 : Territorial Dispute 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In 2333, the C++ Empire and the Ja ...

  8. hihoCoder 1584 Bounce 【数学规律】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1584 : Bounce 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 For Argo, it is very interesting watching a cir ...

  9. hihoCoder 1578 Visiting Peking University 【贪心】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1578 : Visiting Peking University 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Ming is going to travel for ...

随机推荐

  1. Black And White (DFS 训练题)

    G - Black And White ================================================================================ ...

  2. .Net 面试题 汇总(三)

    101.ASP.net的身份验证方式有哪些?分别是什么原理? 答:Windwos(默认)用IIS... From(窗体)用帐户 Passport(密钥) 102.在.net中,配件的意思是? 答:程序 ...

  3. C#中Equals和= =(等于号)的比较)(转载)

    C#中Equals和= =(等于号)的比较) 相信很多人都搞不清Equals和 = =的区别,只是零星的懂一点,现在就让我带大家来进行一些剖析 一.           值类型的比较 对于值类型来说  ...

  4. php简易实现计划任务

    index.php <?php function ceshi(){ $wan = file_get_contents('./wangt_index.txt',true); $jifen = $w ...

  5. 你真的了解React吗

    https://zhufengzhufeng.github.io/zhufengreact/index.html#t21.%E4%BB%80%E4%B9%88%E6%98%AFReact?

  6. python语法图

  7. Virtual Host on Apache(Apache上建立虚拟主机)

    0. Introduction Usually, we want to build two or more websites on a web server, but we have only one ...

  8. Linux/CentOS防CC攻击脚本

    #!/bin/sh cd /var/log/httpd/ cat access_log|awk > a cp /dev/null access_log cp /dev/null error_lo ...

  9. 【BZOJ 1269】文本编辑器

    题目 这些日子,可可不和卡卡一起玩了,原来可可正废寝忘食的想做一个简单而高效的文本编辑器.你能帮助他吗?为了明确任务目标,可可对"文本编辑器"做了一个抽象的定义: Move k:将 ...

  10. 『Golang』在Golang中使用json

    由于要开发一个小型的web应用,而web应用大部分都会使用json作为数据传输的格式,所以有了这篇文章. 包引用 import ( "encoding/json" "gi ...