上一页 1 2 3 4 5 6 7 ··· 14 下一页
摘要: 题目:http://acm.timus.ru/problem.aspx?space=1&num=1286题目要求 p * x1 + q * y1 = abs(ex - sx) && p * x2 + q * y2 = abs(ey - sy)同时成立,设 d = gcd(p,q) ,dx = abs(ex - sx), dy = (ey - sy),如果 (dx % d || dy % d )成立,那么从开始点一定到不了终点,否则 dx /= d, dy /= d, p /= d, q /= d;分情况讨论,详见此出http://shaidaima.com/source 阅读全文
posted @ 2012-10-26 20:27 AC_Girl 阅读(157) 评论(0) 推荐(0) 编辑
摘要: 题目:http://acm.timus.ru/problem.aspx?space=1&num=1430题意很简单,第一感觉是枚举,但是看了一下数据范围,直接没有写,然后感觉 a * x + b * y = n - (某个数)这个方程有解,像是扩展欧几里德,写了之后没过样例。后来还是写了枚举,但是就是超时,网上找了一下,少了一个优化,但是优化的还没看懂,还是HG给讲的才看懂了View Code 1 int main() 2 { 3 ll a,b,n; 4 int x,y; 5 int i; 6 while(cin>>a>>b>>n) 7 { 8 .. 阅读全文
posted @ 2012-10-25 20:35 AC_Girl 阅读(159) 评论(0) 推荐(0) 编辑
摘要: 题目:http://codeforces.com/contest/235/problem/A当给的 n 是奇数时,则是 n * (n - 1) * (n - 2),当是偶数时,则要从 n 往前枚举三个数,求出他们的最小公倍数,感觉最多不会枚举超过10个吧View Code 1 ll gcd(ll a,ll b) 2 { 3 if(!b) return a; 4 else return gcd(b,a % b); 5 } 6 ll lcm(ll a,ll b) 7 { 8 //cout<<"((((\n"; 9 return a / gcd(a,b) * b;1. 阅读全文
posted @ 2012-10-24 19:49 AC_Girl 阅读(320) 评论(0) 推荐(0) 编辑
摘要: 题目:http://acm.hdu.edu.cn/showproblem.php?pid=1695给出a b c d k 在 [a,b] [c,d]内各找一个数,使得gcd(x,y) == k,也就是说 gcd(x / k, y / k) == 1,所以就是在 [1,b / k] [1, d / k]中找互质的对数。容斥原理和欧拉函数的应用,首先在打印素数的同时求出每个数的欧拉函数值,对于[1,b]内的数直接用欧拉数组求互质的对数,对于[b + 1,d]的数用容斥原理求互质对数,首先求出不互质的对数,然后用总的减去不互质的对数。比如说某个数 n ,首先求出 n 的所有因子num, 假设单个因子 阅读全文
posted @ 2012-10-11 17:22 AC_Girl 阅读(160) 评论(0) 推荐(0) 编辑
摘要: 题目:http://acm.timus.ru/problem.aspx?space=1&num=1091题意:从 s 个数里挑出 k 个, 这个 k 个数的共因子大于 1 一共有多少种方法直接暴搜,注意剪枝优化View Code 1 typedef long long ll; 2 const int N = 60; 3 int ans,k,s; 4 bool vis[N]; 5 int flag; 6 int gcd(int a,int b) 7 { 8 if(!b) return a; 9 else return gcd(b,a % b);10 }11 bool juge(... 阅读全文
posted @ 2012-09-28 07:45 AC_Girl 阅读(243) 评论(0) 推荐(0) 编辑
摘要: 题目:http://acm.hdu.edu.cn/showproblem.php?pid=4414简单题目,直接枚举View Code 1 using namespace std; 2 typedef long long ll; 3 const int N = 60; 4 char map[N][N]; 5 int ans,ans1,ans2,ans3,ans4; 6 int n; 7 bool juge(int x,int y,int flag) 8 { 9 //cout<<"x = "<<x<<" "<< 阅读全文
posted @ 2012-09-23 21:35 AC_Girl 阅读(384) 评论(0) 推荐(0) 编辑
摘要: 题目:http://poj.org/problem?id=1111给出你个 n * m的图形,然后给出你鼠标点击的位置(鼠标只可以点击 X),鼠标可以从点击的点往八个方向走,问鼠标可以点击的区域的周长View Code 1 typedef long long ll; 2 const int N = 22; 3 bool vis[N][N]; 4 char map[N][N]; 5 int ans; 6 int n,m; 7 int move[8][2] = {{-1,0},{1,0},{0,-1},{0,1},{-1,-1},{-1,1},{1,1},{1,-1}}; 8 struct no. 阅读全文
posted @ 2012-09-17 11:31 AC_Girl 阅读(148) 评论(0) 推荐(0) 编辑
摘要: 题目:http://acm.hdu.edu.cn/showproblem.php?pid=4291题意和解释网上一搜一大片,以前也做过一个用矩阵乘法求这种题的(这个还要求出嵌套的循环节),可是看到题的时候还是什么也没有想到,对以前的知识掌握的不好,也不会灵活用。。View Code 1 #include <stdio.h> 2 #include <string.h> 3 #include <iostream> 4 #include <algorithm> 5 #include <vector> 6 #include <math. 阅读全文
posted @ 2012-09-17 11:20 AC_Girl 阅读(285) 评论(0) 推荐(0) 编辑
摘要: 题目:http://acm.timus.ru/problem.aspx?space=1&num=1748题意:定义:一个数的的因子个数称为该数的复杂度,给出一个n,求从 1 ~ n 范围内复杂度最大的数,如果有多个相等,输出最小的,并输出因子个数其实就是求反素数的(关于反素数:http://www.cnblogs.com/fxh19911107/archive/2012/07/28/2613150.html),先用求反素数的模板求出在n 范围内复杂度最大的数,然后再把 这个数分解成 素数 乘积的形式,求出因子数View Code 1 typedef long long ll; 2 co 阅读全文
posted @ 2012-09-15 21:40 AC_Girl 阅读(186) 评论(0) 推荐(0) 编辑
摘要: 题目:http://poj.org/problem?id=3661题意:一头牛,给出他运动的时间 ts,在运动时间内,它可以选择跑步,也可以选择休息,如果他跑步疲劳值 +1,如果休息疲劳值 -1,如果它在休息,那么必须疲劳值为0时才能跑步,问到第N秒且疲劳值为0时,牛可以跑得最远距离dp[i][j] 表示 在第 i 秒时 疲劳值为 j 时牛跑的最远距离,那么方程就是 dp[i][j] = dp[i - 1][j - 1] + dis[i] (如果在第 i 秒跑步)dp[i][0] = Max(dp[i][0],dp[i - j][j]) (if( i - j >= j),初始化 dp[i 阅读全文
posted @ 2012-09-15 15:58 AC_Girl 阅读(135) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 ··· 14 下一页