本章题目有毒!!有毒!!!有毒!!!
(基友认出一个东方project,请小伙伴愉快地告诉我剩下的都是什么游戏/番【剧毒出题人)
7.1cirno
//小朋友
#include<stdio.h>
#include<iostream>
using namespace std;
struct student
{
int num;
int score;
}stu[1001];
int main()
{
int n;
int sum;
int i,j;
int p;
cin>>n;
for(i=1;i<=n;i++)
cin>>stu[i].num>>stu[i].score;
for(i=1;i<=n;i++)
{
int a=stu[i].num;
int b;
if(stu[i].num%9==0) stu[i].score=59;
else
{
while(a)
{
if(a%10==9) {stu[i].score=59;break;}
a/=10;
}
}
}
for(i=1;i<=n;i++)
sum+=stu[i].score;
cout<<sum<<endl;
return 0;
}
//犇犇
#include<iostream>
using namespace std;
int main()
{
int o,x,y,i,ans=0,n;
cin>>n;
for (o=0; o<n; o++)
{
cin>>x>>y;
if (x%9==0){ans+=59;continue;}
for (i=x; i; i/=10) if (i%10==9) {y=59; break;}
ans+=y;
}
cout<<ans;
}
7.2 fubuki
//小朋友
#include<stdio.h>
#include<iostream>
using namespace std;
struct star
{
int x;
int y;
}star[501];
int sqr(int x)
{
return x*x;
}
bool check(int x1,int y1,int x2,int y2,int x3,int y3)
{
int a=sqr(x1-x2)+sqr(y1-y2);
int b=sqr(x2-x3)+sqr(y2-y3);
int c=sqr(x3-x1)+sqr(y3-y1);
if((a+b>c)&&(a+c>b)&&(b+c>a))
return true;
return false;
}
int main()
{
int n;
int i,j,k;
int num=0;
bool re;
cin>>n;
for(i=1;i<=n;i++)
cin>>star[i].x>>star[i].y;
for(i=1;i<=n-2;i++)
for(j=i+1;j<=n-1;j++)
for(k=j+1;k<=n;k++)
{
re=check(star[i].x,star[i].y,star[j].x,star[j].y,star[k].x,star[k].y);
if(re) num++;
}
cout<<num<<endl;
}
//犇犇
#include<iostream>
#include<cmath>
using namespace std;
struct fu{
int x;
int y;
}f[500];
int m(int x) {return x*x;}
int brige(fu x,fu y){ return m(x.x-y.x)+m(x.y-y.y);}
int main()
{
int o,x,y,i,j,k,ans=0,n;
cin>>n;
for (o=0; o<n; o++) cin>>f[o].x>>f[o].y;
for (i=0; i<n-2; i++)
for (j=i+1; j<n-1; j++)
for (k=j+1; k<n; k++)
{
int a=brige(f[i],f[j]),b=brige(f[i],f[k]),c=brige(f[j],f[k]);
if ((a+b>c) && (b+c>a) && (c+a>b)) ans++;
}
cout<<ans;
}
7.3 long_distance
//小朋友
#include<stdio.h>
#include<string>
#include<iostream>
using namespace std;
struct race
{
string name;
int mm;
int ss;
}race[101];
int main()
{
int i,j;
char ccc; //存没用的冒号
int n;
int p=1;
cin>>n;
for(i=1;i<=n;i++)
cin>>race[i].name>>race[i].mm>>ccc>>race[i].ss;
for(i=2;i<=n;i++)
{
if(race[i].mm!=race[p].mm) p=race[i].mm<race[p].mm?i:p;
else if(race[i].ss!=race[p].ss) p=race[i].ss<race[p].ss?i:p;
else p=race[i].name<race[p].name?i:p;
}
cout<<race[p].name<<endl;
}
//犇犇
#include<iostream>
#include<cmath>
#include<string>
using namespace std;
struct fu{
string s;
int mm;
int ss;
}read;
int main()
{
int o,x,y,i,j,k,ans=0,n;
char c;
cin>>n;
fu now;now.mm=99; now.ss=99;
for (o=0; o<n; o++)
{
cin>>read.s>>read.mm>>c>>read.ss;
if (read.mm<now.mm|| (read.mm==now.mm &&read.ss<now.ss)) now=read;
}
cout<<now.s;
}
7.4 straight
//小朋友
#include<stdio.h>
#include<iostream>
using namespace std;
int arr[10001];
int main()
{
int n;
int i,j,k;
cin>>n;
for(i=1;i<=n+1;i++)
{
cin>>j>>k;
arr[k]=j;
}
//输入结束
for(i=1;i<=n;i++)
cout<<arr[i]<<endl;
return 0;
}
//犇犇
#include<iostream>
#include<cmath>
#include<string>
using namespace std;
int a[10005];
int main()
{
int n,i,x,y;
cin>>n;
for (i=0; i<n; i++)
{
cin>>x>>y;
a[y]=x;
}
for (i=1; i<=n; i++) cout<<a[i]<<endl;
}
7.5 st
//小朋友
#include<stdio.h>
#include<math.h>
#include<iostream>
using namespace std;
int x[10001];
int y[10001];
int main()
{
int n;
int x0,y0,t0;
int i;
cin>>n;
for(i=1;i<=n;i++)
cin>>x[i]>>y[i];
cin>>x0>>y0>>t0;
for(i=1;i<=n;i++)
{
if((abs(x[i])+abs(y[i]))<=t0)
{
x0+=x[i];
y0+=y[i];
t0-=abs(x[i])+abs(y[i]);
}
}
cout<<x0<<" "<<y0;
return 0;
}
//犇犇
#include<iostream>
#include<cmath>
#include<string>
using namespace std;
struct fu{
int x;
int y;
}a[10005];
int z(int x){ return x<0? -x:x;}
int main()
{
int n,i;
cin>>n;
for (i=0; i<n; i++) cin>>a[i].x>>a[i].y;
fu now;
int m;
cin>>now.x>>now.y>>m;
for (i=0; i<n; i++)
{
int d=z(a[i].x)+z(a[i].y);
if (m>=d) now.x+=a[i].x,now.y+=a[i].y,m-=d;
}
cout<<now.x<<" "<<now.y;
}
7.6 conver
//小朋友
#include<stdio.h>
#include<math.h>
#include<iostream>
using namespace std;
int before[10001];
int after[10001];
int main()
{
int n;
int i,j,k,p;
int a,b;
cin>>n;
for(i=1;i<n;i++)
{
cin>>a>>b;
before[a]=b;
after[b]=a;
}
for(i=1;i<=n;i++)
if(before[i]==0) break;//i为first
cout<<i<<" "<<after[i]<<endl;
for(j=2;j<=n/2;j++)
{
for(p=1;p<=n;p++)
{
if(before[p]==after[i])
{
cout<<p<<" "<<after[p]<<endl;
i=p;
}
}
}
return 0;
}
//犇犇
#include<iostream>
#include<cmath>
#include<string>
using namespace std;
int a[10005],b[10005];
int main()
{
int n,i,x,y;
cin>>n;
for (i=0; i<=10005; i++) a[i]=0,b[i]=0;
for (i=1; i<n; i++)
{
cin>>x>>y;
a[x]=y;
b[y]=x;
}
int now,k;
for (i=1; i<=10000; i++) if (a[i]==0 && b[i]!=0) now=i;
for (i=now,k=1; i; i=b[i],k++)
{
cout<<i;
if (k%2==1) cout<<" ";
else cout<<endl;
}
}
7.7 Spirit
//小朋友
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string>
using namespace std;
struct spirit
{
string name;
int water;
int salt;
}spirit[101];
int main()
{
int n;
char change;
int a,b;
int amount;
int i;
cin>>n;
for(i=1;i<=n;i++)
cin>>spirit[i].name>>spirit[i].water>>spirit[i].salt;
while(cin>>change)
{
if(change=='E') break;
cin>>a>>b>>amount;
if(change=='C')
{
if(b==1) spirit[a].water+=amount;
else spirit[a].salt+=amount;
}
if(change=='Q')
{
if(b==1&&spirit[a].water>=amount) spirit[a].water-=amount;
else if(b==2&&spirit[a].salt>=amount) spirit[a].salt-=amount;
}
if(change=='Z')
{
if(spirit[a].water>=amount)
{
spirit[a].water-=amount;
spirit[b].water+=amount;
}
}
}
for(i=1;i<=n;i++)
cout<<spirit[i].name<<" "<<spirit[i].water+spirit[i].salt<<endl;
return 0;
}
//犇犇
#include<iostream>
#include<cmath>
#include<string>
using namespace std;
struct fu{
string s;
int x;
int y;
}a[105];
int main()
{
int n,i,x,y,m;
char c;
cin>>n;
for (i=1;i<=n; i++) cin>>a[i].s>>a[i].x>>a[i].y;
for (;;)
{
cin>>c;
if (c=='E') break;
cin>>x>>y>>m;
if (c=='C')
if (y==1)
a[x].x+=m;
else a[x].y+=m;
if (c=='Q')
if (y==1)
a[x].x=a[x].x-m>0? a[x].x-m:a[x].x;
else a[x].y=a[x].y-m>0? a[x].y-m:a[x].y;
if (c=='Z')
if (a[x].x>=m) a[x].x-=m,a[y].x+=m;
}
for (i=1; i<=n; i++) cout<<a[i].s<<" "<<a[i].x+a[i].y<<endl;
}
7.8 Average
//小朋友
#include<stdio.h>
#include<iostream>
#include<string>
#include <iomanip>
using namespace std;
struct student
{
string name;
int chin;
int math;
int engl;
double ave;
}stu[101];
int main()
{
freopen("xx.in","r",stdin);
freopen("xx.out","w",stdout);
int n;
int i,k;
int j=1;
int sum[101]={0};
float ave[101]={0};
int win[101]={0};
int end[101]={0};
int max=0;
cin>>n;
for(i=1;i<=n;i++)
{
cin>>stu[i].name>>stu[i].chin>>stu[i].math>>stu[i].engl;
sum[i]=stu[i].chin+stu[i].math+stu[i].engl;
stu[i].ave=(stu[i].chin+stu[i].math+stu[i].engl)/3.0;
}
for(i=1;i<=n;i++)
max=max>sum[i]?max:sum[i];
for(i=1;i<=n;i++)
{
if(max==sum[i])
{
win[j]=i;
j++;
}
}
struct student temp;
int a;
int b;
for(i=1;i<j-1;i++)
for(k=i+1;k<j;k++)
if(stu[win[i]].name>stu[win[k]].name)
{
a=win[i];
b=win[k];
temp=stu[a];
stu[a]=stu[b];
stu[b]=temp;
}
for(i=1;i<j;i++)
{
cout<<stu[win[i]].name<<" "<<stu[win[i]].chin<<" "<<stu[win[i]].math<<" "<<stu[win[i]].engl<<" ";
printf("%.2lf\n",stu[win[i]].ave);
}
return 0;
}
//犇犇
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
struct fu{
string s;
int x;
int y;
int z;
}a[105];
bool cmp(const fu x,const fu y)
{
return x.x+x.y+x.z>y.x+y.y+y.z || (x.x+x.y+x.z==y.x+y.y+y.z && x.s<y.s);
}
int main()
{
int n,i;
cin>>n;
for (i=1; i<=n; i++)
{
cin>>a[i].s>>a[i].x>>a[i].y>>a[i].z;
}
sort(a+1,a+1+n,cmp);
a[0]=a[1];
for (i=1; i<=n; i++)
if (a[i].x+a[i].y+a[i].z==a[0].x+a[0].y+a[0].z)
{
cout<<a[i].s<<" "<<a[i].x<<" "<<a[i].y<<" "<<a[i].z<<" ";
printf("%.2lf\n",(0.0+a[i].x+a[i].y+a[i].z)/3.0);
}
}