CodeForce#172 DIV2

A题我就不放了...岛娘出那个签到都水,大小写转换你也出...

B题代码在上面了...final test 之前我是400...之后我就变200了...一看全都B题被卡掉的...

rating 还+167 莫名其妙真是不知道发生了什么

题意就是给你一个分数a/b,求分母小于c 且能使得abs( a/b - d/c ) 最小的分数...记得最后要化简


坑很多 

第一个: int64

第二个: 分母不能是0

第三个: 循环每次都要GCD...不然可能爆int64

第四个: 0/a = 0/1 (这个真坑)

第五个: 如果abs( a/b - d/c ) 和 abs( a/b - (d+1)/c ) 一样大...要对 d/c 和 (d+1)/c 判断哪个 c 能化得更简  (这个也坑)


不过我莫名其妙AC了...原来是GCD模板酷炫

/*Template*/
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
using namespace std;
//typedef long long LL;
typedef __int64 LL;

//Number
#define EPS  1e-8
#define MAXN 500050
#define INF  (1<<30)
#define MOD  99991
//Math
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a*b/gcd(a,b);}
//Segment Tree
#define L(t) (t << 1)  //左子树
#define R(t) (t << 1 | 1) //右子树
#define Mid(a,b) ((a+b)>>1) 
//BIT
#define lowbit(a) (a&-a)
char a[1005];
int cmp(LL a,LL b,LL c,LL d)
{
    if(a*d-b*c > 0)
        return 1;
    else return 0;
}
int main()
{
//  freopen("in.txt","r",stdin);
//  freopen("out.txt,"w",stdout);
    LL i,x,y,n;
    scanf("%I64d%I64d%I64d",&x,&y,&n);
    LL c=x*n/y;
    LL ansa = min(abs(x*n-y*c),abs(x*n-y*(c+1)));
    LL ansb = y*n;
    LL ans = ansa;
    ansa = ansa/(gcd(ansa,ansb));
    ansb = ansb/(gcd(ans,ansb));
    LL a = (abs(x*n-y*c) > abs(y*(c+1)-x*n) ? c+1 : c) , b=n;
    for(i=n-1;i>=1;i--)
    {
        c = x*i/y;
        LL t = min( abs(x*i-y*c) , abs(x*i-y*(c+1)) );
        LL v = y*i;
        LL tmp = t;
        t = t/gcd(t,v);
        v = v/gcd(tmp,v);
        if(cmp(ansa,ansb,t,v)==1)
        {
            a = (abs(x*i-y*c) > abs(y*(c+1)-x*i) ? c+1 : c);
            b = i;
            ansa = t;
            ansb = v;
        }
    }
    int g = gcd(a,b);
    printf("%I64d/%I64d\n",a/g,b/g);
    return 0;
} 

C题是一个半平面交...要考虑a,b 大小...当时模拟了半天没模拟出个结果...然后就盲cha了...赛后我只看了别人的解法也没重做了

...就贴个别人的代码吧   同一个room的...真是酷炫

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
#define pi 3.1415926535898
int main()
{
    double w1,h1,an;
    cin>>w1>>h1>>an;
    an = min(180-an,an);
    double w = max(w1,h1);
    double h = min(w1,h1);
    double w2 = w/2;
    double h2 = h/2;
    double zhuan = atan(h/w)*2;
    an = an/180 *pi;
    double s;
    if(an>zhuan)
    {
        double l = h/sin(an);
        s = h*l;
    }
    else
    {
        double x;
        double y;
        double a = cos(an)+1;
        double b = sin(an);
        y = (w*b-h*a)/(b*b-a*a);
        x = (a*w - b*h)/(a*a-b*b);
        double f = x*x*sin(an)*cos(an)+y*y*sin(an)*cos(an);
        //cout<<"f"<<f<<"  "<<x<<' '<<y<<' '<<an<<endl;
        s = w*h - f;
    }
    printf("%.9f\n",s);
}

D.E太神了...

D是个单调栈维护的线段树...我不会

E我直接没看...


这么水的我进DIV1肯定要爆零啊...抹泪...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值