[水+数学] fzu oj 2193 So Hard and 2191 完美的数字

2193 So Hard

题意:

化简小数。

思路:

最多不超过9位,那么乘以10^9就好了。

然后注意的就是加一下精度。

代码:

#include"cstdlib"
#include"cstdio"
#include"cstring"
#include"cmath"
#include"queue"
#include"algorithm"
#include"iostream"
#include"map"
#define ll __int64
#define eps 1e-11
using namespace std;
ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        double x;
        scanf("%lf",&x);
        ll fz=(ll)((x+eps)*1000000000);
        ll fm=1000000000;
        ll tep=gcd(fz,fm);
        printf("%I64d/%I64d\n",fz/tep,fm/tep);
    }
    return 0;
}

2191 完美的数字

题意:

[a,b]区间内每个数的完美度的和。

所谓完美度就是X能够分解成多少个A*A*B(0<A<=B)的个数。

思路:

对于[1,x]区间内。

我们枚举A。

因为A<=B 对于每个i,所以若要成立,最小的数是i*i*i

然而我们只要判断i*i*i<=x 的范围内,包含多少个i*i。

对于每个i*i-i+1。

然后相减一下。

代码:

#include"cstdlib"
#include"cstdio"
#include"cstring"
#include"cmath"
#include"queue"
#include"algorithm"
#include"iostream"
#include"map"
#define ll __int64
#define eps 1e-11
using namespace std;
int main()
{
    ll x,y;
    while(scanf("%I64d%I64d",&x,&y)!=-1)
    {
        ll ansx=0,ansy=0;
        x--;
        for(ll i=1;i*i*i<=x;i++) ansx+=x/(i*i)-i+1;
        for(ll i=1;i*i*i<=y;i++) ansy+=y/(i*i)-i+1;
        printf("%I64d\n",ansy-ansx);
    }
    return 0;
}
时间: 2024-11-09 02:07:27

[水+数学] fzu oj 2193 So Hard and 2191 完美的数字的相关文章

LeetCode OJ 之 Single Number III (唯一的数字-三)

题目: Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. For example: Given nums = [1, 2, 1, 3, 2, 5], return [3, 5]. Note: The or

FZU OJ 2147 A-B Game (数学水题)

Problem 2147 A-B Game Accept: 827    Submit: 1940 Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Description Fat brother and Maze are playing a kind of special (hentai) game by two integers A and B. First Fat brother write an integer A on

数学 FZU 2074 Number of methods

题目传送门 1 /* 2 数学:假设取了第i个,有C(n-1)(i-1)种取法 3 则ans = sum (C(n-1)(i-1)) (1<i<=n) 即2^(n-1) 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <cstring> 8 #include <cmath> 9 using namespace std; 10 11 typedef long long ll; 1

FZU OJ 2140 Forever 0.5 (几何)

Problem 2140 Forever 0.5 Accept: 269    Submit: 934    Special Judge Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Description Given an integer N, your task is to judge whether there exist N points in the plane such that satisfy the follo

FZU OJ 2111 Min Number (贪心)

Problem 2111 Min Number Accept: 586    Submit: 1139 Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Description Now you are given one non-negative integer n in 10-base notation, it will only contain digits ('0'-'9'). You are allowed to choo

FZU OJ 2110 Star (计算几何)

Problem 2110 Star Accept: 585    Submit: 1731 Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Description Overpower often go to the playground with classmates. They play and chat on the playground. One day, there are a lot of stars in the s

[思路题+贪心] fzu oj 2197 最小花费

题意: 给一个01串,相邻的01交换代价为X,否则为Y. 问把全部1变到0前面的最小费用. 思路: 对于 01011->11100 如果只靠相邻位移动是需要5步的. 然而不管怎么移动,步数是固定的. 那我们就把最前面的0和最后面的1交换 假设0在i,1在j.我们交换的代价就是min(y,x*(j-i)) 然后累加求和就好了! 很棒的脑洞题! 代码: #include"cstdlib" #include"cstdio" #include"cstring

[bfs] fzu oj 2196 Escape

题意: 一个迷宫里面从开始走到终点的最短步数. 但是这个迷宫里面有许多的火山,会喷岩浆,岩浆每秒向四周蔓延,岩浆到过的点不能走,但是人的移动优先于岩浆. 意思就是,如果某一个时刻,岩浆和人同时到达,那么如果这个点是出口的话,这个点是可以走的. 思路: 首先bfs预处理所有的点火山蔓延到的最小时间,就是将所有火山压进队做bfs. 接着用人做一遍bfs,注意考虑上面的那个人的移动优先于岩浆. 代码: #include"cstdlib" #include"cstdio"

FZU oj 2277 Change 树状数组+dfs序

Problem 2277 Change Time Limit: 2000 mSec    Memory Limit : 262144 KB  Problem Description There is a rooted tree with n nodes, number from 1-n. Root’s number is 1.Each node has a value ai. Initially all the node’s value is 0. We have q operations. T