前言
吃瓜吃瓜
顺便我没有做过原题来试一试能打多少
由于开学机房只剩我一个人只能单挑了_ (:з」∠) _
有的题没时间写就口胡了
Maximum Element In A Stack
Solution
模拟
Code
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
typedef unsigned int u32;
typedef long long ll;
const int N=5e6+5;
int n,p,q,m,ty,ct,top;
u32 SA,SB,SC,mx[N];
u32 rng61() {
SA^=SA<<16;SA^=SA>>5;SA^=SA<<1;
u32 t=SA;
SA=SB;SB=SC;SC^=t^SA;
return SC;
}
void POP() {
if (top) top--;}
void PUSH(u32 x) {
++top;
mx[top]=max(mx[top-1],x);
}
void gen() {
scanf("%d%d%d%d%u%u%u",&n,&p,&q,&m,&SA,&SB,&SC);
top=0;++ct;
ll ans=0;
fo(i,1,n) {
if (rng61()%(p+q)<p) PUSH(rng61()%m+1);
else POP();
ans^=(ll)i*mx[top];
}
printf("Case #%d: %lld\n",ct,ans);
}
int main() {
for(scanf("%d",&ty);ty;ty--) gen();
return 0;
}
Rolling The Polygon
Solution
模拟
Code
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
typedef double db;
const int N=55;
struct P{
db x,y;
P(db _x=0,db _y=0) {
x=_x;y=_y;}
friend P operator + (P a,P b) {
return P(a.x+b.x,a.y+b.y);}
friend P operator - (P a,P b) {
return P(a.x-b.x,a.y-b.y);}
friend P operator * (P a,db b) {
return P(a.x*b,a.y*b);}
friend db operator * (P a,P b) {
return a.x*b.x+a.y*b.y;}
friend db operator ^ (P a,P b) {
return a.x*b.y-a.y*b.x;}
}p[N],q;
db len(P a) {
return sqrt(a*a);}
P rotate(P a,db b) {
return P(a.x*cos(b)+a.y*sin(b),a.y*cos(b)-a.x*sin(b));}
db angle(P a) {
return atan2(a.y,a.x);}
int n,ct;
void solve() {
++ct;
scanf("%d",&n);
fo(i,1,n) scanf("%lf%lf",&p[i].x,&p[i].y);scanf("%lf%lf",&q.x,&q.y);
fo(i,2,n) p[i].x-=p[1].x,p[i].y-=p[1].y;q.x-=p[1].x;q.y-=p[1].y;p[1].x=p[1].y=0;
db age=angle(p[2]);
fo(i,2,n) p[i]=rotate(p[i],age);q=rotate(q,age);
p[n+1]=p[1];p[n+2]=p[2];
db ans=0;
fo(i,2,n+1) {
P dir=p[i+1]-p[i];
db age=angle(dir);
fo(j,1,n+2) if (j!=i) p[j]=p[i]+rotate(p[j]-p[i],age);
q=p[i]+rotate(q-p[i],age);
ans+=fabs(age)*len(q-p[i]);
}
printf("Case #%d: %.3lf\n",ct,ans);
}
int main() {
int ty;
for(scanf("%d",&ty);ty;ty--) solve();
return 0;
}
Caesar Cipher
Solution
模拟
Code
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int N=55;
int n,m,ct;
char s[N],t[N],st[N];
void solve() {
ct++;
scanf("%d%d",&n,&m);
scanf("%s",s+1);scanf("%s",t+1);scanf("%s",st+1);
int shift=t[1]-s[1];if (shift<0) shift+=26;
printf("Case #%d: ",ct);
fo(i,1,m) putchar(st[i]-shift<'A'?st[i]-shift+26:st[i]-shift);
puts("");
}
int main() {
int ty;
for(scanf("%d",&ty);ty;ty--) solve();
return 0;
}
Take Your Seat
Solution
设F[n]表示n个人,最后一个人无法坐到正确位置的答案,则 F [ n ] = ∑ i = 1 n − 1 F [ i ] n F[n]={\sum_{i=1}^{n-1}F[i]\over n} F[n]=n∑i=1n−1F[i]
容易发现F[1]=1,F[2]=F[3]=F[4]=…=F[n]=0.5
第二问就是 1 − ∑ i = 2 m F [ i ] m 1-{\sum_{i=2}^{m}F[i]\over m} 1−m