做了一次月赛,没想到这么难,加上后来补上的题目也只有3个题。第一名也只有4个题啊啊啊啊~.其中两道还是水题。留坑慢慢补上来。

3832 Tilt Cylinder

                              ZOJ Monthly, November 2014-LMLPHP

给定如图所示有盖圆柱体,R,H,水面高度h,倾角a,求水得体积。

分析:明显的数值积分题,这样考虑。圆下底面即A点与地面高度lim1, 圆上底面一点B与地面高度lim2,h所处的范围进行讨论从而确定积分几何体的两边的高度。我们积分的几何体应该是一个圆柱体被削掉一部分了。

h>lim1时,几何体左半部分可以减掉一个圆柱,对剩下部分积分,剩下部分左边截面的高度2*R;否则高度为2*R/cos(a);

h>lim2时,几何体右半部分截面的高度需要计算,为(h-lim2)/cos(a);否则为0.

注意:这里所说的结合体截面的高度是相对与下面的母线而言,并不是对地高度。

然后对上面给出的高度范围结合夹角a进行积分,需要推导截面的面积。最后答案需要加上截掉的那部分完整的圆柱体体积(如果是那种情况的话)。

代码:

 #include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define esp 1e-12
#define lowbit(x) ((x)&(-x))
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define sz(x) ((int)((x).size()))
#define pb push_back
#define pf(x) ((x)*(x)) #define pi acos(-1.0) #define in freopen("solve_in.txt", "r", stdin);
#define out freopen("solve_out.txt", "w", stdout); #define bug(x) printf("Line : %u >>>>>>\n", (x));
#define inf 0x0f0f0f0f
using namespace std; int dblcmp(double x) {
if(fabs(x) < esp) return ;
return x > ? : -;
}
const int N = ;
double R, H, a, h;
double f1(double x) {
double cth = (R-x)/R;
return acos(cth)*pf(R)-(R-x)*sqrt(pf(R)-pf(R-x));
}
double f2(double x) {
double cth = (x-R)/R;
return (pi-acos(cth))*pf(R)+(x-R)*sqrt(pf(R)-pf(x-R));
}
double s1(double l, double r) {
double x = , y = (l-r)/tan(a);
double h0 = (y-x)/N; double res = 0.0;
res = f1(l)+f1(r);
for(int i = ; i <= N; i++) {
if(i < N)
res += *f1(l-(x+i*h0)*tan(a));
res += *f1(l-(x+(*i-)*h0/)*tan(a));
}
return res*h0/; }
double s2(double l, double r) {
double x = , y = (l-r)/tan(a);
double h0 = (y-x)/N; double res = 0.0;
res = f2(l)+f2(r);
for(int i = ; i <= N; i++) {
if(i < N)
res += *f2(l-(x+i*h0)*tan(a));
res += *f2(l-(x+(*i-)*h0/)*tan(a));
}
return res*h0/;
} double getAns(double h0, double h1) {
if(h1 > R) {
return s2(h0, h1);
} else if(h0 < R) {
return s1(h0, h1);
} else {
return s2(h0, R)+s1(R, h1);
}
}
int main() { while(scanf("%lf%lf%lf%lf", &R, &H, &h, &a) == ) {
double res = 0.0;
if(fabs(a) > esp && fabs(a-90.0) > esp) {
a = a*pi/180.0;
double lim2 = sin(a)*H;
double lim1 = *R*cos(a); double h1, h2;
if(h > lim1) {
h1 = *R;
res += pi*pf(R)*(h/sin(a)-*R/tan(a));
} else {
h1 = h/cos(a);
}
if(h > lim2) {
h2 = (h-lim2)/cos(a);
} else {
h2 = 0.0;
}
res += getAns(h1, h2); } else {
if(fabs(a) < esp) {
double Sr;
if(h > R){
Sr = f2(h);
}else{
Sr = f1(h);
}
res = Sr*H;
} else {
res = pi*pf(R)*h;
}
}
printf("%.12f\n", res);
}
return ;
}

3839 Poker Face

分析:第n个是将第n/2个倒插进去然后加上眼睛等部分。

代码:

 #include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define esp 1e-8
#define lowbit(x) ((x)&(-x))
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define sz(x) ((int)((x).size()))
#define pb push_back
#define in freopen("solve_in.txt", "r", stdin);
#define out freopen("solve_out.txt", "w", stdout); #define bug(x) printf("Line : %u >>>>>>\n", (x));
#define inf 0x0f0f0f0f
#define Fill(x, b1, b2, l, r) {\
for(int i = ; i < l; i++)\
maze[x][i+b1][b2] = maze[x][i+b1][b2+r-] = '*';\
for(int i = ; i < r; i++)\
maze[x][b1][i+b2] = maze[x][b1+l-][i+b2] = '*';\
}\ using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef map<string, int> MPS; using namespace std;
const int maxn = ;
char s[maxn][maxn] = {
{"********"}, {"*** ***"}, {"*** ***"}, {"*** ***"}, {"* **** *"}, {"* * * *"},
{"* * * *"}, {"********"}
}; char maze[][maxn][maxn]; int popcount(int x){
int ans = ;
while(){
if(x&) break;
ans++;
x >>= ;
}
return ans;
}
void dfs(int n){
if(n <= ) return;
int x = popcount(n);
// cout << x << endl;
for(int i = ; i < n; i++) for(int j = ; j < n; j++)
maze[x][i][j] = ' ';
Fill(x, , , n, n)
int st1 = n/, st2 = st1+n/;
Fill(x, n/, st1, n/+, n/)
Fill(x, n/, st2, n/+, n/)
dfs(n>>);
int b1 = n/, b2 = n/;
int nn = n>>;
for(int i = ; i < (n>>); i++)
for(int j = ; j < (n>>); j++){
maze[x][b1+i][b2+j] = maze[x-][nn--i][nn--j];
}
}
int main() { int n;
for(int i = ; i < ; i++)
strcpy(maze[][i], s[i]);
dfs(); while(scanf("%d", &n), n >= ) {
// cout << n <<endl;
int x = popcount(n);
// cout << x << endl;
for(int i = ; i < n; i++)
puts(maze[x][i]);
puts("");
}
return ;
}

3838 Infusion Altar

分析:对每个点和其对称点访问一遍,将数目最多的那种保留,其他全部替换成这种。

代码:

 #include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define esp 1e-8
#define lowbit(x) ((x)&(-x))
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define sz(x) ((int)((x).size()))
#define pb push_back
#define in freopen("solve_in.txt", "r", stdin);
#define out freopen("solve_out.txt", "w", stdout); #define bug(x) printf("Line : %u >>>>>>\n", (x));
#define inf 0x0f0f0f0f
using namespace std;
const int maxn = ;
char maze[maxn][maxn];
int vis[maxn][maxn];
vector<char> tmp;
int n; void dfs(int x, int y){
if(vis[x][y]) return;
vis[x][y] = ;
tmp.pb(maze[x][y]);
dfs(y, x);
dfs(n--y, n--x);
dfs(n--x, y);
dfs(x, n--y);
}
int main(){ int T;
for(int t = scanf("%d", &T); t <= T; t++){
scanf("%d", &n);
int ans = ;
for(int i = ; i < n; i++)
scanf("%s", maze[i]);
// for(int i = 0; i < n; i++)
// cout << maze[i];
memset(vis, , sizeof vis);
for(int i = ; i < n; i++)for(int j = ; j < n; j++){
if(vis[i][j]) continue;
tmp.clear();
dfs(i, j);
sort(tmp.begin(), tmp.end());
int jj;
int mx = ;
for(int ii = ; ii < sz(tmp); ii = jj){
int ok = ;
for(jj = ii; jj < sz(tmp) && tmp[jj] == tmp[ii]; jj++)
ok++;
mx = max(ok, mx);
}
ans += sz(tmp)-mx;
}
cout << ans << endl;
}
return ;
}
05-11 08:13