文章目录
A - Mishka and Game
题目链接:A - Mishka and Game
- 思路:水题。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
int n, a, b;
cin >> n;
int counta = 0, countb = 0;
for(int i=1; i<=n; i++)
{
cin >> a >> b;
if(a>b) counta++;
else if(a<b) countb++;
}
if(counta>countb) cout << "Mishka" << endl;
else if(counta<countb) cout << "Chris" << endl;
else cout << "Friendship is magic!^^" << endl;
return 0;
}
B - Mishka and trip
题目链接:B - Mishka and trip
参考博文:cf B. Mishka and trip (数学)
- 思路:主要思路是先算中心城市的有关道路的魅力值,然后在算普通城市有关且与中心城市无关的道路的魅力值。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAX = 100005;
typedef long long LL;
LL c[MAX], id[MAX];
int vis[MAX];//记录是否是中心城市
int main()
{
int n, k, idx;
LL sum = 0, ans = 0, sum2 = 0;
scanf("%d%d", &n, &k);
for(int i=1; i<=n; i++)
{
scanf("%lld", &c[i]);
sum += c[i];//所有城市的魅力值
}
memset(vis, 0, sizeof(vis));
for(int i=1; i<=k; i++)
{
scanf("%lld", &id[i]);
vis[id[i]] = 1;
}
//中心城市有关道路的魅力值
LL tol = 0;
for(int i=1; i<=k; i++)
{
tol += c[id[i]];
ans += c[id[i]]*(sum-tol);
}
//计算环路(取出与中心城市有关的道路)
if(!vis[1] && !vis[n]) ans += c[1]*c[n];
for(int i=1; i<n; i++)
{
if(!vis[i]&&!vis[i+1]) ans += c[i]*c[i+1];
}
printf("%lld\n", ans);
return 0;
}
C - Chris and Road
题目链接:C - Chris and Road
参考博文:Codeforces Round #365 (Div. 2) – C. Chris and Road (思路水题)
- 思路:看到此题,一脸蒙蔽。以为是计算几何,结果是一个思路奇特的模拟题。
可以枚举车的所有顶点(x,y),求出当人走到(0,y)时,(x,y)顶点走到了距离Y轴还多远,这样把这个距离的最大值和最小值求出来,Max,Min,- 如果Min大于0,表示最能撞到人的顶点都在人的右边,那这个车肯定撞不到人,直接就是w/u!
- 如果Min小于0,并且Max 大于0,那么你必须等车会撞到你的点过去后再走,答案就是Max/v + w/u!
- 如果Max也小于0,那么说明这个车开的太快了~,你还没走多久,他已经过去了,这时输出w/u!
比较时精度也是一个卡点。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const double eps = 1e-8;
const int INF = 1<<29;
int main()
{
int n, w, v, u;
double x, y;
cin >> n >> w >> v >> u;
double Min = INF*1.0, Max = 0.0;
for(int i=1; i<=n; i++)
{
cin >> x >> y;
double x1 = x-v*y/u;
if(x1>Max) Max = x1;
if(x1<Min) Min = x1;
}
if(Min>=-eps || Max<=-eps) printf("%.10f\n", w/(u*1.0));
else printf("%.10f\n", w/(u*1.0)+Max/v);
return 0;
}
D - Mishka and Interesting sum
题目链接:D - Mishka and Interesting sum