1003 Fall with Trees(结论)
找规律
得出S=(4*k-10+3*(2)^(2-k))*d*h
#include<iostream>
#include<cstdio>
#include<math.h>
using namespace std;
int main()
{
int T;
scanf_s("%d", &T);
while (T--)
{
int k;
scanf_s("%d", &k);
int x, y;
int xl, yl, xr, yr;
scanf_s("%d%d%d%d%d%d", &x, &y, &xl, &yl, &xr, &yr);
int h;
h = y - yl;
double d;
d = (xr - xl)*1.0 / 2;
double sum;
sum = 4 * k - 10 + 3 * pow(2, 2 - k);
printf("%.3lf\n", sum * h * d);
}
}
1008 Smzzl with Greedy Snake (模拟)
模拟题,设每次初始坐标(x,y),初始方向d,每次食物位置为(tx,ty)
然后分类讨论初始d=0,d=1,d=2,d=3的情况,注意改变头的方向
最后将x=tx,y=ty,d=td(即将上一个食物的位置变为下一个食物的初始位置)
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
ios::sync_with_stdio(0); cin.tie(0);
int T;
cin >> T;
while (T--)
{
string ans = "";
int x, y, d;
cin >> x >> y >> d;
int n;
cin >> n;
while (n--)
{
int tx1;
int ty1;
int p1;
int p2;
int td;
cin >> tx1 >> ty1;
int xd = abs(tx1 - x);
int yd = abs(ty1 - y);
if (tx1 > x)
p1 = 1;
if (tx1 < x)
p1 = 3;
if (ty1 > y)
p2 = 0;
if (ty1 < y)
p2 = 2;
if (d == 0){
if (p2 == 0){
for (int i = 1; i <= yd; i++) ans+="f";
if (p1 == 1) { ans += "c"; td = 1; }
if (p1 == 3) { ans += "u"; td = 3; }
for (int i = 1; i <= xd;i++) ans += "f";
}
else{
if (p1 == 1) ans += "c";
if (p1 == 3) ans += "u";
for (int i = 1; i <= xd; i++) ans += "f";
if (p1 == 1) ans += "c";
if (p1 == 3) ans += "u";
for (int i = 1; i <= yd; i++) ans += "f"; td = 2;
}
}
if (d == 2){
if (p2 == 2)
{
for (int i = 1; i <= yd; i++) ans+="f";
if (p1 == 1) { ans += "u"; td = 1; }
if (p1 == 3) { ans += "c"; td = 3; }
for (int i = 1; i <= xd; i++) ans += "f";
}
else
{
if (p1 == 1) ans += "u";
if (p1 == 3) ans += "c";
for (int i = 1; i <= xd; i++) ans += "f";
if (p1 == 1) ans += "u";
if (p1 == 3) ans += "c";
for (int i = 1; i <= yd; i++) ans += "f"; td = 0;
}
}
if (d == 1)
{
if (p1 == 1) {
for (int i = 1; i <= xd; i++) ans += "f";
if (p2 == 2) { ans += "c"; td = 2; }
if (p2 == 0) { ans += "u"; td = 0; }
for (int i = 1; i <= yd; i++) ans += "f";
}
else {
if (p2 == 0) ans += "u";
if (p2 == 2) ans += "c";
for (int i = 1; i <= yd; i++) ans += "f";
if (p2 == 0) ans += "u";
if (p2 == 2) ans += "c";
for (int i = 1; i <= xd; i++) ans += "f"; td = 3;
}
}
if (d == 3)
{
if (p1 == 3) {
for (int i = 1; i <= xd; i++) ans += "f";
if (p2 == 2) { ans += "u"; td = 2; }
if (p2 == 0) { ans += "c"; td = 0; }
for (int i = 1; i <= yd; i++) ans += "f";
}
else {
if (p2 == 0) ans += "c";
if (p2 == 2) ans += "u";
for (int i = 1; i <= yd; i++) ans += "f";
if (p2 == 0) ans += "c";
if (p2 == 2) ans += "u";
for (int i = 1; i <= xd; i++) ans += "f"; td = 1;
}
}
x = tx1;
y = ty1;
d = td;
}
cout <<ans<<endl;
}
}
1007 Link with Limit (图论找环)
题意:使得图中所有环均值相等。