8-15-小练

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

A.HDU 1042   N!

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

代码:

 #include <iostream>
#include <cstdio>
using namespace std; int a[]; int main()
{
int n,i,j;
while(~scanf("%d",&n))
{
if(n== || n==){printf("1\n"); continue;}
a[]=; //用来记录数字的位数
a[]=;
for(i=;i<=n;i++)
{
int sum=;
for(j=;j<=a[];j++)
{
int temp=a[j]*i+sum;
sum=temp/;
a[j]=temp%;
}
while(sum)
{
a[j]=sum%;
a[]=j;
sum/=;
j++;
}
}
for(i=a[];i>=;i--)
printf("%d",a[i]);
printf("\n");
}
return ;
}

//memory:372KB     time:1546ms

B.HDU 1050      Moving Tables

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

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

 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std; class N
{
public:
int x,y,id;
}a[]; bool comp(N w,N q)
{
return w.x<q.x;
} int main()
{
int t,n,i,j;
scanf("%d",&t);
while(t--)
{
memset(a,,sizeof(a));
scanf("%d",&n);
for(i=;i<n;i++)
{
int x,y;
scanf("%d%d",&x,&y);
if(x<y)
{a[i].x=x;a[i].y=y;}
else
{a[i].x=y;a[i].y=x;}
}
sort(a,a+n,comp);
int sum=;
for(i=;i<n;i++)
if(a[i].id==)
{
a[i].id=;
int minn=a[i].y;
for(j=i+;j<n;j++)
if(a[j].id== && a[j].x>minn)
{
a[j].id=;
minn=a[j].y;
}
sum++;
}
printf("%d\n",sum*);
}
return ;
}

网上的AC代码:

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std; #define maxn 460 int main()
{
int t,i,n,b,e;
scanf("%d",&t);
while (t--)
{
int c[]={},m=;
scanf("%d",&n);
while (n--)
{
scanf("%d%d",&b,&e);
if (b>e)
{
i=b;
b=e;
e=i;
}
for (i=(b-)/;i<=(e-)/;++i)
++c[i];
}
for (i=;i<;++i)
if (m<c[i])m=c[i];
printf("%d\n",*m);
}
return ;
}

//memory:228KB   time:0ms

C.HDU 1181     变形课

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

BFS~

 #include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std; const int inf=<<;
bool vis[];
int a[][];
char c[]; void bfs()
{
int q1=,q2,i;
queue<int> q;
memset(vis,,sizeof(vis));
q.push(q1);
vis[q1]=;
while(!q.empty())
{
q2=q.front();
q.pop();
for(i=;i<;i++) //i代表的是字母【example:i=0,代表A】
if(!vis[i] && a[q2][i]==)
{
if(i=='m'-'a')
{
puts("Yes.");
return;
}
q.push(i);
vis[i]=;
}
}
puts("No.");
return;
} int main()
{
int t,n,i,j,len;
memset(a,,sizeof(a));
while(~scanf("%s",c))
{
len=strlen(c);
a[c[]-'a'][c[len-]-'a']=; //建立字母转换的图
if(c[]=='')
{
bfs();
memset(a,,sizeof(a));
}
}
return ;
}

//memory:268KB     time:0ms

D.HDU 3501      Calculation 2

是考欧拉函数~

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

代码:

 #include <iostream>
#include <cstdio>
using namespace std; #define M 1000000007 int eular(__int64 n) //欧拉函数
{
int i,ans=n;
for(i=;i*i<=n;i++)
if(n%i==)
{
ans-=ans/i;
while(n%i==)
n/=i;
}
if(n>) ans-=ans/n;
return ans;
} int main()
{
__int64 n,ans;
while(scanf("%I64d",&n),n)
{
ans=n*(n+)/-n;
ans-=eular(n)*n/;
ans%=M;
printf("%I64d\n",ans);
}
return ;
}

//memory:228KB    time:15ms

E.HDU 2601       An easy problem

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

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

代码:

 #include<stdio.h>
#include<math.h>
int main()
{ int t;
scanf("%d",&t);
while(t--)
{
__int64 n;
scanf("%I64d",&n);
n++;
__int64 i;
__int64 sum=;
for(i=;i*i<=n;i++)
if(n%i==)
sum++;
printf("%I64d\n",sum); }
return ;
}

//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. python 下载安装及setuptools应用

    1.首先下载python安装程序,下载地址:https://www.python.org/download/releases/2.7.8/ 如下图: 因为我的机器是32位的就选择了Windows x8 ...

  2. vs2013下使用Assist X的破解方法

    Assist X的破解下载:http://pan.baidu.com/s/1kTnDH23 密码:j9jp 01.安装,点击VA_X_Setup2042.exe 安装 02.破解 找到这样的目录:C: ...

  3. mysql查询结果中文显示成了问号

    在mysql的配置文件my.ini中的[mysqld]项中加这两句 character-set-server = utf8 collation-server = utf8_general_ci 在任务 ...

  4. HTML中的转义字符

    HTML常用符号: 显示一个空格    < 小于 < <> 大于 > >& &符号 & &" 双引号 " &qu ...

  5. What's this?(js)

    What's this? 由于运行期绑定的特性,JavaScript 中的 this 含义非常多,它可以是全局对象.当前对象或者任意对象,这完全取决于函数的调用方式 随着函数使用场合的不同,this的 ...

  6. 如何才能学到Qt的精髓——信号槽之间的无关性,提供了绝佳的对象间通讯方式,QT的GUI全是自己的一套,并且完全开源,提供了一个绝好机会窥视gui具体实现

    姚冬,中老年程序员 叶韵.KY Xu.赵奋强 等人赞同 被邀请了很久了,一直在思考,今天终于下决心开始写回答. 这个问题的确是够大的,Qt的代码规模在整个开源世界里也是名列前茅的,这么大的项目其中的精 ...

  7. HDU 2493 Timer 数学(二分+积分)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2493 题意:给你一个圆锥,水平放置,圆锥中心轴与地面平行,将圆锥装满水,在圆锥某一表面开一个小洞,流出来 ...

  8. linux内存管理机制

    物理内存和虚拟内存 我们知道,直接从物理内存读写数据要比从硬盘读写数据要快的多,因此,我们希望所有数据的读取和写入都在内存完成,而内存是有限的,这样就引出了物理内存与虚拟内存的概念. 物理内存就是系统 ...

  9. 【HDOJ】1016 Prime Ring Problem

    经典DP,写的可能麻烦了一些. #include <stdio.h> #define false 0 #define true 1 ]; ]; ]; void DFS(int, int, ...

  10. 我的第一个Hibernate程序

    1.建表建序列(所用数据库为Oracle,数据库名为XE,创建用户hibernate,密码为123456) conn system/manager; ; grant connect to hibern ...