意外的變藍了,才解了兩道 ,以爲要掉rating呢
最近好幾次CF都掛在精度上了,這次也是,B題又忘記用64位了 導致錯了幾次
A題
首字母大寫
#include <iostream>
#include<cstdio>
#include<cstring>
#include<stdlib.h>
using namespace std;
char str[1010];
int main()
{
int i,j,k,n;
cin>>str;
if(str[0]>='a'&&str[0]<='z')
str[0] = str[0]-32;
puts(str);
return 0;
}
B題 枚舉從1到N 注意一下精度
#include <iostream>
#include<cstdio>
#include<cstring>
#include<stdlib.h>
#include<algorithm>
#define INF 100000
using namespace std;
#define LL __int64
LL gcd(LL a,LL b)
{
return b==0? a:gcd(b,a%b);
}
void change(LL x,LL y)
{
int i,j;
LL k = min(x,y);
for(i = 2 ; i <= k ; i++)
{
while(x%i==0&&y%i==0)
{
x = x/i;
y = y/i;
}
if(x<i||y<i)
break;
}
printf("%I64d/%I64d\n",x,y);
}
int main()
{
int i,j;
LL k,n,x,y,d,t1,t2,a,yy;
double s;
cin>>x>>y>>n;
if(y<=n)
{
change(x,y);
return 0;
}
double mi = 10000000000;
for(i = 1; i <= n ; i++)
{
k = y*i/gcd(y,i);
LL kk = k/y*x;
yy = k/i;
if(abs(kk-kk/yy*yy)>abs(kk-(kk/yy+1)*yy))
{
a = kk/yy+1;
d = abs(kk-(kk/yy+1)*yy);
}
else
{
a = kk/yy;
d = abs(kk-(kk/yy)*yy);
}
s = d*INF*1.0/k;
if(mi>s)
{
t1 = a;
t2 = i;
mi = s;
}
}
change(t1,t2);
return 0;
}