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语言学习笔记(34)System.Environment
System.Environment getArgs :: IO [String] getProgName :: IO String getExecutablePath :: IO FilePath ...
- EL表达式获取请求
1EL 表达式语法: ${ EL 表达式} 它的特点: 1自动转换类型, 2使用简单. 2 EL表达式具有类型无关性,可以使用“.”或者“[]”操作符在相应的作用域(page , requ ...
- redmine邮件配置
网上找了半天,有很多答案,最后自己测试找出一个解决办法. 1.找到安装位置 D:\Bitnami\redmine-2.5.2-2\apps\redmine\htdocs\config下的文件confi ...
- MyBatis 通用Mapper接口 Example的实例
一.mapper接口中的方法解析 mapper接口中的函数及方法 方法 功能说明 int countByExample(UserExample example) thorws SQLException ...
- easyUIDataGrid分页
package com.cn.eport.util; import java.util.List; /** * * * @author zh * */ public class DataGrid im ...
- 正向工程configuration配置连接
在执行正向工程的时候需要用到这个关键词里面的configure();方法, 这个方法有好几个重构, 都是参数不一样的, 也可以空着不写, 不写的话就会默认去找hibernate.cfg.xml这个文件 ...
- tag-SMASS-1
SMASS 是在vasp的DFTMD中决定着系综的类型,在手册中给出的该参数具体信息如下: SMASS = -3 | -2 | -1 | [real] ≥ 0 Default: SMASS = -3 ...
- 分享至微信、QQ、微博、复制链接
var share = { "tit": '您的朋友分享了文章', "desc": '分享来自百度文库,包含...', "pic": 'ht ...
- Windows phone 自定义用户控件(UserControl)——ColorPicker
编码前 学习Windows phone自定义用户控件,在<WPF编程宝典>学习的小例子.并根据windows phone稍微的不同,做了点修改.ColorPicker(颜色拾取器):拥有三 ...
- 122. Best Time to Buy and Sell Stock II (Array;Greedy)
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...