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 ...
随机推荐
- Haskell语言学习笔记(24)MonadWriter, Writer, WriterT
MonadWriter 类型类 class (Monoid w, Monad m) => MonadWriter w m | m -> w where writer :: (a,w) -& ...
- 迷你MVVM框架 avalonjs 1.4.1发布
以后有关avalon的版本升级消息,全部改放到这里 重构parseHTML,让其支持xhtml 强化 ms-duplex-number拦截器 添加data-duplex-number辅助指令 值为st ...
- 使用css技术代替传统的frame技术
http://www.dynamicdrive.com/style/layouts/item/css-left-frame-layout/ <!--Force IE6 into quirks m ...
- 吴裕雄 数据挖掘与分析案例实战(5)——python数据可视化
# 饼图的绘制# 导入第三方模块import matplotlibimport matplotlib.pyplot as plt plt.rcParams['font.sans-serif']=['S ...
- zset
zset sorted set,有序集合 元素为string类型 元素具有唯一性,不重复 每个元素都会关联一个double类型的score,表示权重,通过权重将元素从小到大排序 说明:没有修改操作 增 ...
- Spring Cloud feign
Spring Cloud feign使用 前言 环境准备 应用模块 应用程序 应用启动 feign特性 综上 1. 前言 我们在前一篇文章中讲了一些我使用过的一些http的框架 服务间通信之Http框 ...
- hdoj1257(DP-LIS/贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1257 方法1--贪心: 定义一个数组f[30005],由于题目没给数据量大小,故为了保险,开到最大(高 ...
- swift iOS开发初步使用
使用Xcode6-Beta 创建一个swift空的工程,新建一个UIViewController,语言选择swift. 在MainViewController.swift 添加如下代码,声明变量及cl ...
- centos7 源码编译安装TensorFlow CPU 版本
一.前言 我们都知道,普通使用pip安装的TensorFlow是万金油版本,当你运行的时候,会提示你不是当前电脑中最优的版本,特别是CPU版本,没有使用指令集优化会让TensorFlow用起来更慢. ...
- 关于swift语言中导入OC三方类找不到头文件的解决方法
首先我遇到的问题是这样的: 我之前封装的OC类,我导入现在的swift工程中,然后建立桥接文件,在Swift的控制器中可以找到这个OC写的东西. 但是问题来了,当你使用cocoapods导入的OC三方 ...