感恩,期待更好
第一题(100分):归一化处理
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+10;
int a[1010];
double f[1010];
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n; cin>>n;
ll sum=0;
for(int i=1;i<=n;i++)
{
cin>>a[i];
sum+=a[i];
}
double b=(sum*1.0)/n;
double d=0;
for(int i=1;i<=n;i++)
{
d+=(a[i]-b)*(a[i]-b);
}
d=(d*1.0)/n;
for(int i=1;i<=n;i++)
{
f[i]=((a[i]-b)*1.0)/(sqrt(d));
cout<<setiosflags(ios::fixed)<<setprecision(16)<<f[i]<<endl;
}
return 0;
}
第二题(100分): 寻宝!大冒险!
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+10;
int b[60][60];
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n,l,s;
cin>>n>>l>>s;
vector<pair<int,int>> v;
map<pair<int,int>,int> mp;
for(int i=1;i<=n;i++)
{
int x,y;
cin>>x>>y;
pair<int,int> p=make_pair(x,y);
v.push_back(p);
mp[p]=1;
}
int num=0;
for(int i=s;i>=0;i--)
{
for(int j=0;j<=s;j++)
{
cin>>b[i][j];
if(b[i][j]) num++;
}
}
int res=0;
for(int i=0;i<v.size();i++)
{
pair<int,int> p=v[i];
int x=p.first,y=p.second;
int sum=0,f=1;
for(int j=0;j<=s;j++)
{
for(int k=0;k<=s;k++)
{
if(b[j][k]==1 && x+j>=0 && x+j<=l && y+k>=0 && y+k<=l)
{
pair<int,int> tmp=make_pair(x+j,y+k);
if(mp[tmp]==1) sum++;
else
{
f=0; break;
}
}
else if(b[j][k]==1 && !( x+j>=0 && x+j<=l && y+k>=0 && y+k<=l))
{
f=0; break;
}
else if(b[j][k]==0 && x+j>=0 && x+j<=l && y+k>=0 && y+k<=l)
{
pair<int,int> tmp=make_pair(x+j,y+k);
if(mp[tmp]==1)
{
f=0; break;
}
}
else if(b[j][k]==0 && !(x+j>=0 && x+j<=l && y+k>=0 && y+k<=l))
{
f=0; break;
}
}
}
if(sum==num && f==1) res++;
}
cout<<res<<endl;
return 0;
}
第三题(100分): 角色授权
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=510;
struct Chara
{
string name;
unordered_map<string,int> op;
unordered_map<string,int> stype;
unordered_map<string,int> sname;
unordered_map<string,int> user;
unordered_map<string,int> group;
}chara[N];
unordered_map<string,int> charamp;
unordered_map<string,set<int>> mp;
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n,m,q;
cin>>n>>m>>q;
for(int i=1;i<=n;i++)
{
string name; cin>>name;
chara[i].name=name;
charamp[name]=i;
int nv; cin>>nv;
while(nv--)
{
string tmp;
cin>>tmp;
chara[i].op[tmp]=1;
}
int no; cin>>no;
while(no--)
{
string tmp;
cin>>tmp;
chara[i].stype[tmp]=1;
}
int nn; cin>>nn;
while(nn--)
{
string tmp;
cin>>tmp;
chara[i].sname[tmp]=1;
}
}
for(int i=1;i<=m;i++)
{
string name; cin>>name;
int id=charamp[name];
int ns; cin>>ns;
while(ns--)
{
char type; cin>>type;
string tmp; cin>>tmp;
if(type=='u')
{
chara[id].user[tmp]=1;
}
else
{
chara[id].group[tmp]=1;
mp[tmp].insert(id);
}
}
}
while(q--)
{
string name; cin>>name;
int ng; cin>>ng;
set<int> have;
while(ng--)
{
string tmp; cin>>tmp;
if(mp[tmp].size()>0)
{
have.insert(mp[tmp].begin(),mp[tmp].end());
}
}
string opname,sourcetype,sourcename;
cin>>opname>>sourcetype>>sourcename;
int flag=0;
for(int i=1;i<=n;i++)
{
if(chara[i].user[name]==1)
{
if(chara[i].op[opname]==0 && chara[i].op["*"]==0)
continue;
if(chara[i].stype[sourcetype]==0 && chara[i].stype["*"]==0)
continue;
if(chara[i].sname.size()>0 && chara[i].sname[sourcename]==0)
continue;
flag=1;
cout<<1<<endl;
break;
}
else
{
if(have.count(i))
{
if(chara[i].op[opname]==0 && chara[i].op["*"]==0)
continue;
if(chara[i].stype[sourcetype]==0 && chara[i].stype["*"]==0)
continue;
if(chara[i].sname.size()>0 && chara[i].sname[sourcename]==0)
continue;
flag=1;
cout<<1<<endl;
break;
}
}
}
if(flag==0) cout<<0<<endl;
}
return 0;
}
第四题(15分):光线追踪
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1010;
struct Node
{
int x1,x2,y1,y2;
double a;
int f;
}node[N];
vector<int> have;
bool judge(int x,int y,int x1,int y1,int x2,int y2)
{
if((x==x1 && y==y1) || (x==x2 && y==y2)) return false;
int k=(y2-y1)/(x2-x1);
int b=y1-k*x1;
if(k*x+b==y)
{
int xmax=max(x1,x2);
int xmin=min(x1,x2);
int ymax=max(y1,y2);
int ymin=min(y1,y2);
if(x>xmin && x<xmax && y>ymin && y<ymax) return true;
else return false;
}
return false;
}
vector<int> fun(int x,int y,int d,double I,int t,int chx,int chy)
{
vector<int> res;
int cnt=0;
x+=chx,y+=chy;
cnt++;
while(cnt<t)
{
if(I<1) return res;
int flag=0;
for(int i=0;i<have.size();i++)
{
int id=have[i];
if(node[id].f==1)
{
if(judge(x,y,node[id].x1,node[id].y1,node[id].x2,node[id].y2))
{
flag=1;
int k=(node[id].y2-node[id].y1)/(node[id].x2-node[id].x1);
if(k==-1)
{
if(d==0)
{
d=3; y--;
chx=0; chy=-1;
}
else if(d==1)
{
d=2; x--;
chx=-1; chy=0;
}
else if(d==2)
{
d=1; y++;
chx=0; chy=1;
}
else if(d==3)
{
d=0; x++;
chx=1; chy=0;
}
}
else if(k==1)
{
if(d==0)
{
d=1; y++;
chx=0; chy=1;
}
else if(d==1)
{
d=0; x++;
chx=1; chy=0;
}
else if(d==2)
{
d=3; y--;
chx=0; chy=-1;
}
else if(d==3)
{
d=2; x--;
chx=-1; chy=0;
}
}
I=I*node[id].a;
break;
}
}
}
if(flag==0)
{
x+=chx,y+=chy;
}
cnt++;
}
for(int i=0;i<have.size();i++)
{
int id=have[i];
if(node[id].f==1)
{
if(judge(x,y,node[id].x1,node[id].y1,node[id].x2,node[id].y2))
{
I=I*node[id].a;
break;
}
}
}
if(I<1) I=0;
int Ires=I;
if(Ires==0) return res;
res.push_back(x);
res.push_back(y);
res.push_back(Ires);
return res;
}
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int m; cin>>m;
for(int i=1;i<=m;i++)
{
int op; cin>>op;
if(op==1)
{
int x1,x2,y1,y2;
double a;
cin>>x1>>y1>>x2>>y2>>a;
node[i].a=a;
node[i].x1=x1;
node[i].x2=x2;
node[i].y1=y1;
node[i].y2=y2;
node[i].f=1;
have.push_back(i);
}
else if(op==2)
{
int k; cin>>k;
node[k].f=0;
}
else if(op==3)
{
int x,y,d,t;
double I;
cin>>x>>y>>d>>I>>t;
int chx=0,chy=0;
if(d==0)
{
chx=1; chy=0;
}
else if(d==1)
{
chx=0; chy=1;
}
else if(d==2)
{
chx=-1; chy=0;
}
else if(d==3)
{
chx=0; chy=-1;
}
vector<int> res=fun(x,y,d,I,t,chx,chy);
if(res.size()==0) cout<<0<<" "<<0<<" "<<0<<endl;
else cout<<res[0]<<" "<<res[1]<<" "<<res[2]<<endl;
}
}
return 0;
}