A题:
就是三点求圆心
#include <bits/stdc++.h>
using namespace std;
struct Point
{
double x,y;
};
Point get_pc1(Point p1, Point p2, Point p3) //求圆心
{
double a, b, c, d, e, f;
Point p;
a = 2*(p2.x-p1.x);
b = 2*(p2.y-p1.y);
c = p2.x*p2.x+p2.y*p2.y-p1.x*p1.x-p1.y*p1.y;
d = 2*(p3.x-p2.x);
e = 2*(p3.y-p2.y);
f = p3.x*p3.x+p3.y*p3.y-p2.x*p2.x-p2.y*p2.y;
p.x = (b*f-e*c)/(b*d-e*a);
p.y = (d*c-a*f)/(b*d-e*a);
// r = sqrt((p.x-p1.x)*(p.x-p1.x)+(p.y-p1.y)*(p.y-p1.y));//半径
return p;
}
int main()
{
Point a,b,c;
cin>>a.x>>a.y;
cin>>b.x>>b.y;
cin>>c.x>>c.y;
Point O=get_pc1(a,b,c);
printf("%.3lf %.3lf\n",O.x,O.y);
}
C题:
避免边界的麻烦计算,直接用前缀和的思想来进行计算
#include <bits/stdc++.h>
#define int long long
using namespace std;
int get_time(int x)
{
int ans=0;
int t=x/60;
ans+=t*50;
if(x%60>=50) ans+=50;
else ans+=x%60;
return ans;
}
signed main()
{
int ans,t1,t2,time;
while(cin>>t1>>t2) {
// cout<<t2%60<<endl;
int a=get_time(t2);
int b=get_time(t1-1);
cout<<a-b<<endl;
}
}
D题:
开始看到最优还以为找最短路的条数有多少条,后来一直过不了,再读题才知道我们可以控制发出时间,那么就是求到达n这个点一共有多少不同的条数了。因为题目是满足拓扑序,所以按照拓扑序DP过去就可以了。
#include <bits/stdc++.h>
using namespace std;
const int N=4e5+7;
int ne[N],head[N],e[N],cnt,d[N];
int f[N];
const int mod=20010905;
queue<int> q;
void add(int a,int b)
{
e[cnt]=b,ne[cnt]=head[a],head[a]=cnt++;
}
void top_sort()
{
while(!q.empty()){
int u=q.front(); q.pop();
for(int i=head[u];~i;i=ne[i]){
int j=e[i];
d[j]--;
if(d[j]==0) q.push(j);
f[j]=(f[u]+f[j])%mod;
}
}
}
int main()
{
memset(head,-1,sizeof head);
int n,m; cin>>n>>m;
for(int i=1;i<=m;i++){
int a,b,c; scanf("%d%d%d",&a,&b,&c);
add(a,b);
d[b]++;
}
q.push(1);
f[1]=1;
top_sort();
cout<<f[n]<<endl;
return 0;
}
E题:
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int n;
cin>>n;
double zongxuef=0;
double fs=0;
for(int i=1;i<=n;i++)
{
int x;
double xuef,pshf,pp,midf,midp,lastf,lastp;
cin>>x>>xuef>>pshf>>pp>>midf>>midp>>lastf>>lastp;
if(x==2)continue;
else
{
zongxuef+=xuef;
double score=pshf*pp+midf*midp+lastf*lastp;
if(score-(int)score>=0.5)score=(int)score+1;
else score=(int)score;
fs+=score*xuef;
}
}
fs/=zongxuef;
cout<<fixed<<setprecision(2)<<fs;
}
F题:
规律题
#include <bits/stdc++.h>
#define int long long
using namespace std;
int arr[100];
signed main()
{
string str;
cin>>str;
char c=str[str.size()-1];
int a=c-'0';
if(a%2==0){
cout<<1<<endl;
}else cout<<-1<<endl;
}
G题:
质因数分解,然后判断个数的奇偶性。
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n; scanf("%d",&n);
vector<int> g;
for(int i=2;i<=sqrt(n)&&n!=1;i++){
if(n%i==0){
while(n%i==0) {
g.push_back(i);
n /= i;
}
}
}
if(n!=1) g.push_back(n);
if(g.size()==1){
cout<<"Nancy"<<endl;
}else{
if(g.size()%2==0) cout<<"Johnson"<<endl;
else cout<<"Nancy"<<endl;
}
return 0;
}
I题:
dp[i] 代表的是iloveyou字符串以第i个下标结尾的方案数。
开始没注意写成了乘法,但是因为子序列有前后顺序,所以不能用乘法。
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod=20010905;
int f[10];
signed main()
{
string str;
cin>>str;
for(int i=0;i<(int )str.size();i++){
if(str[i]=='i'||str[i]=='I') f[1]=(f[1]+1)%mod;
if(str[i]=='l'||str[i]=='L') f[2]=(f[1]+f[2])%mod;
if(str[i]=='o'||str[i]=='O') f[3]=(f[2]+f[3])%mod;
if(str[i]=='v'||str[i]=='V') f[4]=(f[3]+f[4])%mod;
if(str[i]=='e'||str[i]=='E') f[5]=(f[5]+f[4])%mod;
if(str[i]=='y'||str[i]=='Y') f[6]=(f[6]+f[5])%mod;
if(str[i]=='o'||str[i]=='O') f[7]=(f[7]+f[6])%mod;
if(str[i]=='u'||str[i]=='U') f[8]=(f[8]+f[7])%mod;
}
cout<<f[8]<<endl;
}
J题:
简单bfs
#include <bits/stdc++.h>
using namespace std;
const int N=1e2+3;
struct node{
int x,y,z,step;
};
char c[N][N][N];
int dis[N][N][N],vis[N][N][N];
int dir[6][3]={1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1};
int main()
{
int n;
int i,j,k;
int tx,ty,tz;
cin>>n;
for(i=1;i<=n;i++){
for(j=1;j<=n;j++) {
for(k=1;k<=n;k++) {
cin>>c[i][j][k];
}
}
}
memset(dis,-1,sizeof(dis));
queue<node>q;
q.push(node{1,1,1,1});
vis[1][1][1]=1;
dis[1][1][1]=1;
while(!q.empty()) {
node u=q.front();q.pop();
for(i=0;i<6;i++) {
tx=dir[i][0]+u.x;
ty=dir[i][1]+u.y;
tz=dir[i][2]+u.z;
if(tx<1||tx>n||ty<1||ty>n||tz<1||tz>n||vis[tx][ty][tz]||c[tx][ty][tz]=='*')
continue;
vis[tx][ty][tz]=1;
// if(tx+ty+tz==6)
//cout<<"*"<<c[tx][ty][tz];
dis[tx][ty][tz]=u.step+1;
// q.push(node{tx,ty,tz,u.step+1});
q.push(node{tx,ty,tz,u.step+1});
}
}
cout<<dis[n][n][n];
return 0;
}
来源:CSDN
作者:行走天涯的豆沙包
链接:https://blog.csdn.net/weixin_42979819/article/details/104108413