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 ...
随机推荐
- sql server 2000能否得到一个表的最后更新日期?
如果是SQL 2005 或 2008.运行下面的代码.就可以看到从上次启动SQL 服务以来,某个表的使用情况,包括select/update/delete/insert. SELECT * FROM ...
- subnet partition
例1:本例通过子网数来划分子网,未考虑主机数. 一家集团公司有12家子公司,每家子公司又有4个部门.上级给出一个172.16.0.0/16的网段,让给每家子公司以及子公司的部门分配网段. 思路:既然有 ...
- python爬虫(5)--正则表达式
正则表达式是对字符串操作的一种逻辑公式,就是用事先定义好的一些特定字符.及这些特定字符的组合,组成一个“规则字符串”,这个“规则字符串”用来表达对字符串的一种过滤逻辑. 1.了解正则表达式 正则表达式 ...
- oracle 网络环境配置
PLSQL Developer连接Oracle11g 64位数据库配置详解 最近换了台64bit的电脑,所以oracle数据库也跟着换成了64bit的,不过 问题也随之产生,由于plsql devel ...
- 唯快不破:Web应用的13个优化步骤
https://mp.weixin.qq.com/s?__biz=MjM5NzA1MTcyMA==&mid=2651163004&idx=2&sn=2b1be8014abf19 ...
- Ubuntu安装libevent
背景: 版本: libevent 2.1.6beta linux下: 按照github官方做法: $ sudo apt-get install openssl $ mkdir build && ...
- PAT L2-005 集合相似度(模拟集合set)
给定两个整数集合,它们的相似度定义为:Nc/Nt*100%.其中Nc是两个集合都有的不相等整数的个数,Nt是两个集合一共有的不相等整数的个数.你的任务就是计算任意一对给定集合的相似度. 输入格式: 输 ...
- codeblocks不支持c++11的有效解决办法
首先cb支持c++11编程开发,但是不支持编译 看了网上好多,说setting里面设置一下就好了,16.01版本我安装了带ide的不带IDE的,安了好多次,但是就是没有那个选项 找不到c++11那个选 ...
- python作业之修改用户配置文件
用户的配置文件如下 backend oldboy school school1 age 21 weight 210 qq 550176565 iphone 139987676backend oldgi ...
- Linux升级Ruby
一.简介 Ruby 是一种开源的面向对象程序设计的服务器端脚本语言,在 20 世纪 90 年代中期由日本的松本行弘(まつもとゆきひろ/Yukihiro Matsumoto)设计并开发.在 Ruby 社 ...