ACM STEPS——Chapter Two——Section One
数学题小关,做得很悲剧,有几道题要查数学书。。。
记下几道有价值的题吧
The area(hdoj 1071)
http://acm.hdu.edu.cn/showproblem.php?pid=1071
直线方程易求,曲线方程要推公式。。。设y=a*x^2+b*x+c,则顶点坐标为(-b/(2a),4ac-b^2)/(4a)),又从题目中已知顶点坐标为(x1,y1),以及另一点(x2,y2),则有
y2=a*x2*x2+b*x2+c
y1=a*x1*x1+b*x1+c
x1=-b/(2*a)
所以a=(y2-y1)/((x2-x1)*(x2-x1))
求出a后,剩下的b和c就没问题,而面积直接用定积分的定义搞定
AC CODE:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
int MIN(int a,int b) { if( a<b )
return a; else return b; }
int MAX(int a,int b) { if( a>b )
return a; else return b; }
#define CLR(NAME,VALUE) memset(NAME,VALUE,sizeof(NAME))
using namespace std;
const int N=10000;
int main() {
int ca,i;
double
x1,y1,x2,y2,x3,y3,m,n,res,dtmp,x,a,b,c;
cin>>ca;
while( ca-- ) {
cin>>x1>>y1>>x2>>y2>>x3>>y3;
//y=m*x+n
m=(y2-y3)/(x2-x3);
n=y3-m*x3;
//y=a*x^2+b*x+c
a=(y2-y1)/((x2-x1)*(x2-x1));
b=-2*a*x1;
c=y1-a*x1*x1-b*x1;
x=x2;
res=0;
dtmp=(x3-x2)/N;
for(i=0;i<N;++i) {
x+=dtmp;
res+=dtmp*(a*x*x+b*x+c-m*x-n);
}
printf("%.2lf\n",res);
}
return 0;
}
找新朋友(hdoj 1286)
http://acm.hdu.edu.cn/showproblem.php?pid=1286
定义:设φ(m)表示不超过m,而和m互质的正整数的个数,则φ(m)称为欧拉函数
计算公式:若a=(p1^a1)*(p2^a2)…(pn^an) 是 a 的标准分解式,则
φ(a)= a*(1-1/p1)*(1-1/p2)…(1-1/pn)
//pi是质数,且是a的因数
然后先求出范围内的质数,代公式,搞定
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
int MIN(int a,int b) { if( a<b
) return a; else return b;
}
int MAX(int a,int b) { if( a>b )
return a; else return b; }
#define CLR(NAME,VALUE) memset(NAME,VALUE,sizeof(NAME))
using namespace std;
const int N=32768+2;
bool notPrim[N];
int main() {
int ca,n,i,j;
for(i=2;i<N;++i) {
if( !notPrim[i] ) {
for(j=i;i*j<N;++j) {
notPrim[i*j]=true;
}
}
}
cin>>ca;
while( ca-- ) {
cin>>n;
double res=n;
for(i=2;i<=n;++i) {
if(
!notPrim[i] && n%i==0 ) {
res=res*(1-1.0/i);
}
}
cout<<res<<endl;
}
return 0;
}
整数对(hdoj 1271)
http://acm.hdu.edu.cn/showproblem.php?pid=1271
这个其实可以当作是一类题来处理,即去掉数字中一位数后,再OOXX的题
假设A是原来的数,B是去掉A中一位数后的数,N=A+B
A=a*10^(k+1)+b*10^k+c //假设要去掉的是第k+1位数,而b就是该位的数字,a是b之前的数字,c是b之后的数字
B=a*10^k+c
N=a*11*10^k+b*10^k+2*c
从枚举10^k入手,将第三式右边除以10^k后,得到a*11+b,那么要得到a,只需再除以11,而要b,则对11取余。但这只是2*c无进位的情况,当有进位时,要将得到的b的值再减1。再下来就是验证c是否存在就可以了。
#include<set>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
int MIN(int a,int b) { if( a<b
) return a; else return b;
}
int MAX(int a,int b) { if( a>b )
return a; else return b; }
#define CLR(NAME,VALUE) memset(NAME,VALUE,sizeof(NAME))
using namespace std;
int main() {
int n,i,k,a,b,c;
while( cin>>n,n )
{
set<int> con;
for(k=1;k<=n;k*=10) {
a=(n/k)/11;
//无进位
b=(n/k) %
11;
if(
b<10 && (a!=0||b!=0)
) {
c=n-a*11*k-b*k;
if( c%2==0 ) {
con.insert(a*k*10+b*k+c/2);
}
}
//有进位
b=(n/k) %
11-1;
if(
b>=0 && (a!=0||b!=0)
) {
c=n-a*11*k-b*k;
if( c%2==0 ) {
con.insert(a*10*k+b*k+c/2);
}
}
}
if( con.size()==0 ) {
printf("No
solution.\n");
continue;
}
i=0;
for(set<int>::iterator
index=con.begin();index!=con.end();++index,++i) {
printf("%d%c",*index,i==con.size()-1?'\n':' ');
}
}
return 0;
}
Leftmost Digit(HDOJ
1060)
http://acm.hdu.edu.cn/showproblem.php?pid=1060
N^N=a*10^k
//0<a<1,k为N^N的位数
两边取以10为底的对数
N*log10(N)=log10(a)+k
k=log10(N^N)=N*log10(N)取整
则log10(a)=N*log10(N)-取整(N*log10(N))
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
int MIN(int a,int b) { if( a<b
) return a; else return b;
}
int MAX(int a,int b) { if( a>b )
return a; else return b; }
#define CLR(NAME,VALUE) memset(NAME,VALUE,sizeof(NAME))
using namespace std;
int main() {
int ca,n;
double x;
cin>>ca;
while( ca-- ) {
cin>>n;
x=n*log10((double)n);
x=x-(__int64)x;
cout<<(int)pow(10.0,x)<<endl;
}
return 0;
}
ACM STEPS——Chapter Two——Section One的更多相关文章
- MathType 插入定义的chapter and section break后无法隐藏
每一章标题后面插入一个“Next Section Break”,这样定稿后各章文件组合为总文件后,方程编号会自动递增,如果已经插入了默认的“Equation Chapter 1 Section 1”, ...
- Word中去除/删除/删掉Equation Chapter (Next) Section 1
实际问题如图显示 Equation Chapter (Next) Section 1 . 具体操作步骤如下: 1.Word的"格式"菜单--"样式和格式",出现 ...
- mathtype 章节号 Equation Chapter 1 Section 1 的去除
mathtype 章节号 Equation Chapter 1 Section 1 的去除 转:http://hi.baidu.com/17ximm/blog/item/2882413e92fc96c ...
- HDOJ acm steps 3.1.1
(都是递推求值,呵呵,好开心- - ) 今天又是在自习室通宵(文明玩的停不下来了) 游戏玩完想想该水题了,于是打开了HDOJ的ACM STEPS(这是个好东西,就像他的名字,一步步来的) 2.3.x貌 ...
- hdu ACM Steps Section 1 花式A+B 输入输出格式
acm与oi很大的一个不同就是在输入格式上.oi往往是单组数据,而acm往往是多组数据,而且题目对数据格式往往各有要求,这8道a+b(吐槽..)涉及到了大量的常用的输入输出格式.https://wen ...
- hdu acm steps Big Event in HDU
上网搜了一下这道题的解法,主要有两个方法,一种是采用母函数的方法,一种是采用0/1背包的方法. 先说一下母函数,即生成函数,做个比喻,母函数就是一个多项式前面的系数的一个整体的集合,而子函数就是这个多 ...
- ACM思维题训练 Section A
题目地址: 选题为入门的Codeforce div2/div1的C题和D题. 题解: A:CF思维联系–CodeForces -214C (拓扑排序+思维+贪心) B:CF–思维练习-- CodeFo ...
- ACM Steps 2.1.8
小数化分数2 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- ACM Steps 2.1.7
Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
随机推荐
- 类定义,创建/销毁OC对象
类定义 1 OC类分为2个文件,一个是.h文件,一个是.m文件: 2 .h文件存放类.函数声明: 3 .m文件类的具体实现: 4 类声明使用关键字@interface.@end来声明: 5 类实现使用 ...
- 吴裕雄 数据挖掘与分析案例实战(2)——python数据结构及方法、控制流、字符串处理、自定义函数
list1 = ['张三','男',33,'江苏','硕士','已婚',['身高178','体重72']]# 取出第一个元素print(list1[0])# 取出第四个元素print(list1[3] ...
- thymeleaf 拼接字符串与变量
参考https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html <span th:text="'The name o ...
- cmd无法输入中文解决方案
1.regedit 2.选中HKEY_CURRENT_USER-Console,找到LoadConIme,双击,设置值为1,十六进制 3.此时应该已经ok了.如还不行,看一下%systemroot%\ ...
- Java学生信息增删改查(并没用数据库)
一个泛型的应用,Java版本增删改查,写的简陋,望批评指正 2016-07-02 很久前写的一个程序了.拿出来存一下,不是为了展示啥,自己用的时候还可以看看.写的很粗糙. import java.io ...
- centos7下mysql5.6的主从复制
一.mysql主从复制介绍 mysql的主从复制并不是数据库磁盘上的文件直接拷贝,而是通过逻辑的binlog日志复制到要同步的服务器本地,然后由本地的线程读取日志里面的sql语句,重新应用到mysql ...
- uploadify 文件上传报http 302错误
uploadify文件上传会报http 302错误,在配置文件中将处理上传的通用类取消验证, 假设上传的通用处理类是fileUpload.ashx,则在配置文件同添加下面过滤配置能解决问题. < ...
- Spring基于AspectJ的AOP的开发之AOP的相关术语
1. Joinpoint(连接点) -- 所谓连接点是指那些被拦截到的点.在spring中,这些点指的是方法,因为spring只支持方法类型的连接点(任何一个方法都可以称为连接点) 2. Pointc ...
- Canvas游戏计算机图形教程
TechbrooD 主站 WOW 登录 注册 0首页 1简介 1.1WWW 技术变迁和生态 1.2WWW 学习建议 1.3WWW 互联网基础知识 1.4WWW Web 1.5 WWW Web ...
- MapReduce 计算模式
声明:本文摘录自<大数据日知录——架构与算法>一书. 较常见的计算模式有4类,实际应用中大部分ETL任务都可以归结为这些计算模式或者变体. 1.求和模式 a.数值求和 比如我们熟悉的单词计 ...