8-15-小练

这次的题目......只觉得泪奔啊......T T

A.HDU 1042   N!

因为0<=n<=1000,故一定要用数组或字符串【同样因为n<=1000故用数组就够了~~~】。

代码:

  1. #include <iostream>
  2. #include <cstdio>
  3. using namespace std;
  4.  
  5. int a[];
  6.  
  7. int main()
  8. {
  9. int n,i,j;
  10. while(~scanf("%d",&n))
  11. {
  12. if(n== || n==){printf("1\n"); continue;}
  13. a[]=; //用来记录数字的位数
  14. a[]=;
  15. for(i=;i<=n;i++)
  16. {
  17. int sum=;
  18. for(j=;j<=a[];j++)
  19. {
  20. int temp=a[j]*i+sum;
  21. sum=temp/;
  22. a[j]=temp%;
  23. }
  24. while(sum)
  25. {
  26. a[j]=sum%;
  27. a[]=j;
  28. sum/=;
  29. j++;
  30. }
  31. }
  32. for(i=a[];i>=;i--)
  33. printf("%d",a[i]);
  34. printf("\n");
  35. }
  36. return ;
  37. }

//memory:372KB     time:1546ms

B.HDU 1050      Moving Tables

下面是网上的代码,我做这道题时,自己的思路与下面代码的思路略有不同......我是把区间从大到小排了后再找同一时间能作业的区间,看要找几次;而网上的代码的思路则是找重叠区域,看重叠的次数。其实,实质上,我的“找的次数”与网上的“重叠次数”都是相同的,但不知道为什么WA,但测试了好几组数据都是对的......

我的代码如下【还望高手不吝赐教】:

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <cstring>
  5. using namespace std;
  6.  
  7. class N
  8. {
  9. public:
  10. int x,y,id;
  11. }a[];
  12.  
  13. bool comp(N w,N q)
  14. {
  15. return w.x<q.x;
  16. }
  17.  
  18. int main()
  19. {
  20. int t,n,i,j;
  21. scanf("%d",&t);
  22. while(t--)
  23. {
  24. memset(a,,sizeof(a));
  25. scanf("%d",&n);
  26. for(i=;i<n;i++)
  27. {
  28. int x,y;
  29. scanf("%d%d",&x,&y);
  30. if(x<y)
  31. {a[i].x=x;a[i].y=y;}
  32. else
  33. {a[i].x=y;a[i].y=x;}
  34. }
  35. sort(a,a+n,comp);
  36. int sum=;
  37. for(i=;i<n;i++)
  38. if(a[i].id==)
  39. {
  40. a[i].id=;
  41. int minn=a[i].y;
  42. for(j=i+;j<n;j++)
  43. if(a[j].id== && a[j].x>minn)
  44. {
  45. a[j].id=;
  46. minn=a[j].y;
  47. }
  48. sum++;
  49. }
  50. printf("%d\n",sum*);
  51. }
  52. return ;
  53. }

网上的AC代码:

  1. #include <iostream>
  2. #include <algorithm>
  3. #include <stdio.h>
  4. #include <string.h>
  5. using namespace std;
  6.  
  7. #define maxn 460
  8.  
  9. int main()
  10. {
  11. int t,i,n,b,e;
  12. scanf("%d",&t);
  13. while (t--)
  14. {
  15. int c[]={},m=;
  16. scanf("%d",&n);
  17. while (n--)
  18. {
  19. scanf("%d%d",&b,&e);
  20. if (b>e)
  21. {
  22. i=b;
  23. b=e;
  24. e=i;
  25. }
  26. for (i=(b-)/;i<=(e-)/;++i)
  27. ++c[i];
  28. }
  29. for (i=;i<;++i)
  30. if (m<c[i])m=c[i];
  31. printf("%d\n",*m);
  32. }
  33. return ;
  34. }

//memory:228KB   time:0ms

C.HDU 1181     变形课

题意:就是在一堆的字符串中看“b”是否能转换成“m”。【转换关系:每一个字符串的首字母可以变为尾字母】

BFS~

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <queue>
  4. #include <cstring>
  5. using namespace std;
  6.  
  7. const int inf=<<;
  8. bool vis[];
  9. int a[][];
  10. char c[];
  11.  
  12. void bfs()
  13. {
  14. int q1=,q2,i;
  15. queue<int> q;
  16. memset(vis,,sizeof(vis));
  17. q.push(q1);
  18. vis[q1]=;
  19. while(!q.empty())
  20. {
  21. q2=q.front();
  22. q.pop();
  23. for(i=;i<;i++) //i代表的是字母【example:i=0,代表A】
  24. if(!vis[i] && a[q2][i]==)
  25. {
  26. if(i=='m'-'a')
  27. {
  28. puts("Yes.");
  29. return;
  30. }
  31. q.push(i);
  32. vis[i]=;
  33. }
  34. }
  35. puts("No.");
  36. return;
  37. }
  38.  
  39. int main()
  40. {
  41. int t,n,i,j,len;
  42. memset(a,,sizeof(a));
  43. while(~scanf("%s",c))
  44. {
  45. len=strlen(c);
  46. a[c[]-'a'][c[len-]-'a']=; //建立字母转换的图
  47. if(c[]=='')
  48. {
  49. bfs();
  50. memset(a,,sizeof(a));
  51. }
  52. }
  53. return ;
  54. }

//memory:268KB     time:0ms

D.HDU 3501      Calculation 2

是考欧拉函数~

来源:http://gzhu-101majia.iteye.com/blog/1296950

代码:

  1. #include <iostream>
  2. #include <cstdio>
  3. using namespace std;
  4.  
  5. #define M 1000000007
  6.  
  7. int eular(__int64 n) //欧拉函数
  8. {
  9. int i,ans=n;
  10. for(i=;i*i<=n;i++)
  11. if(n%i==)
  12. {
  13. ans-=ans/i;
  14. while(n%i==)
  15. n/=i;
  16. }
  17. if(n>) ans-=ans/n;
  18. return ans;
  19. }
  20.  
  21. int main()
  22. {
  23. __int64 n,ans;
  24. while(scanf("%I64d",&n),n)
  25. {
  26. ans=n*(n+)/-n;
  27. ans-=eular(n)*n/;
  28. ans%=M;
  29. printf("%I64d\n",ans);
  30. }
  31. return ;
  32. }

//memory:228KB    time:15ms

E.HDU 2601       An easy problem

i*i+i+j=n可以写成:(i+1)*(j+1)=n-1

式子改成了上面这个模样......答案就华华丽丽的出来了~~╮(╯▽╰)╭

代码:

  1. #include<stdio.h>
  2. #include<math.h>
  3. int main()
  4. {
  5.  
  6. int t;
  7. scanf("%d",&t);
  8. while(t--)
  9. {
  10. __int64 n;
  11. scanf("%I64d",&n);
  12. n++;
  13. __int64 i;
  14. __int64 sum=;
  15. for(i=;i*i<=n;i++)
  16. if(n%i==)
  17. sum++;
  18. printf("%I64d\n",sum);
  19.  
  20. }
  21. return ;
  22. }

//memory:228KB   time:2000ms

8-15-Exercise的更多相关文章

  1. C - The C Answer (2nd Edition) - Exercise 1-5

    /* Modify the temperature conversion program to print the table in reverse order, that is, from 300 ...

  2. MIT 6.828 JOS学习笔记5. Exercise 1.3

    Lab 1 Exercise 3 设置一个断点在地址0x7c00处,这是boot sector被加载的位置.然后让程序继续运行直到这个断点.跟踪/boot/boot.S文件的每一条指令,同时使用boo ...

  3. Think Python - Chapter 15 - Classes and objects

    15.1 User-defined typesWe have used many of Python’s built-in types; now we are going to define a ne ...

  4. 《how to design programs》15章 相互引用的数据定义

    由结构体组成的表与结构体中的表. 在用追溯形式建立家家谱树时,我们通常从某个后代除法,依次处理它的父母,组父母等.而构建树时,我们会不断添加谁是谁的孩子,而不是写出谁是谁的父母,从而建立一颗后代家谱树 ...

  5. CMSC 216 Exercise #5

    CMSC 216 Exercise #5 Spring 2019Shell Jr (”Shellito”) Due: Tue Apr 23, 2019, 11:30PM1 ObjectivesTo p ...

  6. 软件测试:3.Exercise Section 2.3

    软件测试:3.Exercise Section 2.3 /************************************************************ * Finds an ...

  7. (14)Why some people find exercise harder than others

    https://www.ted.com/talks/emily_balcetis_why_some_people_find_exercise_harder_than_others/transcript ...

  8. 【DeepLearning】Exercise:Self-Taught Learning

    Exercise:Self-Taught Learning 习题链接:Exercise:Self-Taught Learning feedForwardAutoencoder.m function [ ...

  9. TEXT 15 A text a day...

    TEXT 15 A text a day... Mar 24th 2006 From The Economist print edition The medical uses of mobile ph ...

  10. 18 A GIF decoder: an exercise in Go interfaces 一个GIF解码器:go语言接口训练

    A GIF decoder: an exercise in Go interfaces  一个GIF解码器:go语言接口训练 25 May 2011 Introduction At the Googl ...

随机推荐

  1. Pair Project: Elevator Scheduler [电梯调度算法的实现和测试][关于电梯调度算法的附加思考]:刘耀先-11061183,罗凡-11061174

    本文为对于电梯调度算法的三个附加题思考 1.改进电梯调度的interface 设计, 让它更好地反映现实, 更能让学生练习算法, 更好地实现信息隐藏和信息共享. <1>进一步提高API定义 ...

  2. 服务器环境搭建系列(一)-Apache篇

    一.Apache 1.解压缩tar包httpd-2.2.22.tar.gz,这里默认放在/opt下 tar -zxvf httpd-2.2.22.tar.gz 2.进入解压缩后的文件夹 cd http ...

  3. writeToFile 读写文件问题

    关于 writeToFile 读写文件:当字典中键值对以 Model(例如:studentModel)为值时发现 Dictionary 调用 writeToFile 方法无法生成 plist 文件,经 ...

  4. POJ1177+线段树+扫描线

    思路: 以y的值进行离散化 根据x的值 对每一条y轴边进行处理,如果是"左边"则插入,是"右边"则删除. /* 扫描线+线段树+离散化 求多个矩形的周长 */ ...

  5. SQL跨表更新

    [一篮饭特稀原创,转载请注明出自http://www.cnblogs.com/wanghafan/p/4384039.html]  前提:两张表要更新的字段.关联字段结构一致 更新库:FJPDI_TZ ...

  6. DHTMLX 前端框架 建立你的一个应用程序 教程(五)--添加一个表格Grid

    表格例子 样本如下: 我们这篇介绍的是dhtmlxGrid  组件. 它支持4种数据格式:XML, JSON, CSV, JSArray. 添加表格到布局的单元格中去: 1.使用attachGrid( ...

  7. *[topcoder]LittleElephantAndBalls

    http://community.topcoder.com/stat?c=problem_statement&pm=12758&rd=15704 topcoder的题经常需要找规律,而 ...

  8. phpexcelreader超级简单使用

    phpexcelreader超级简单使用 该php类可以到官网下载:http://www.codeplex.com/PHPExcel,下载的文件不能直接使用要看下面的备注. 备注: 1.要将olere ...

  9. redis消息队列

    http://blog.csdn.net/21aspnet/article/details/7455032

  10. OpenSSL 拒绝服务漏洞

    漏洞名称: OpenSSL 拒绝服务漏洞 CNNVD编号: CNNVD-201312-058 发布时间: 2013-12-05 更新时间: 2013-12-05 危害等级:    漏洞类型:   威胁 ...