牛客月赛21 (题解报告)

A-Audio

思路分析:

代码:

B-Bits(待补)

C-Channels

思路分析:

代码 :

D-DDoS 

思路分析:

代码: 

E-Exams

思路分析:

代码: 

F- Fool Problem

思路分析:

代码:

 G-Game

思路分析:

代码:

H- ”Happy New Year!“

思路分析:

I-I love you 

思路分析:

代码:

J-Jelly

思路分析:

代码


A-Audio

思路分析:

就是简单的求一个点到三角形三点的距离相等即可

求重心问题 求二条线找交点即可 

代码:

int main(){
//     cout<<endl;
    double x1,y1,x2,y2,x3,y3;
    cin>>x1>>y1>>x2>>y2>>x3>>y3;
    double x4,y4,x5,y5;
    x4=(x1+x2)/2;
    y4=(y1+y2)/2;
    y5=(y1+y3)/2;
    x5=(x1+x3)/2;
//    cout<<"x4 y4"<<x4<<" "<<y4<<endl;
//    cout<<"x5 y5"<<x5<<" "<<y5<<endl;
    double k1=(y2-y1)/(x2-x1);
    double k11=-(1/k1);
    double b1=y4-k11*x4;
    double k2=(y3-y1)/(x3-x1);
    double k22=-(1/k2);
    double b2=y5-k22*x5;
//    cout<<"k1x+b1 "<<k1<<" "<<b1<<endl;
//    cout<<"k2x+b2 "<<k2<<" "<<b2<<endl;
    double xx=(b2-b1)/(k11-k22);
    double yy=k11*(xx)+b1;
//    cout<<xx<<" "<<yy<<endl;
    printf("%.3f %.3f",xx,yy);
    
}

B-Bits(待补)

C-Channels

思路分析:

可以用类似前缀和的思想来解决

代码 :

ll gettime(ll x){
    int t=x%60;
    return 50*(x/60)+((t<=50)?t:50);
}
int main(){
    ll t1,t2;
    
    while (scanf("%lld %lld",&t1,&t2)==2) {
        cout<<gettime(t2)-gettime(t1-1)<<endl;
    }
    
}

D-DDoS 

思路分析:

题意就是让求1-n的不同路径有几条 

这样我们可以用拓扑+dp来解决

dp[next]+=dp[x]

最后答案就是dp[1][n]

代码: 

const int MAX=100005;
const int mod=20010905;
vector<int>v[MAX];

int n,m;
int in[MAX];
ll f[MAX];
int main(){
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b,c;
        cin>>a>>b>>c;
        v[a].push_back(b);
        in[b]++;
    }
    queue<int>q;
    for(int i=1;i<=n;i++){
        if(!in[i]){
            q.push(i);
        }
    }
    f[1]=1;
    while (!q.empty()) {
        int u=q.front();
        q.pop();
        for(int i=0;i<v[u].size();i++){
            int ne=v[u][i];
            f[ne]+=f[u];
            f[ne]%=mod;
            in[ne]--;
            if(!in[ne]){
                q.push(ne);
            }
        }
    }
    cout<<f[n]<<endl;
}

E-Exams

思路分析:

其实就是一个模拟题 没有难度

四舍五入可以用round也可以(ans+0.5 )/x

代码: 

int main() {
    double credit, tot=0.0, s, p, sum1=0.0, sum2=0.0;
    int n, t;
    scanf("%d", &n);
    while(n --) {
        tot = 0.0;
        scanf("%d %lf", &t, &credit);
        for (int i = 0; i < 3; i ++) {
            scanf("%lf %lf", &s, &p);
            tot += s * p;
        }
        if (t != 2) {
            sum1 += credit;
            sum2 += (int)(tot+0.5) * credit; 
        }
    }

    double ans = sum2 / sum1;
    ans = (int)(ans*100+0.5) / 100.0;
    printf("%.2lf\n", ans);
    return 0;
}

F- Fool Problem

思路分析:

数据过大直接算不太可能 先打表找找规律

const int MAX=10010;
ll f[MAX];
ll ff(ll x){
    if(f[x]!=0) return f[x];
    return f[x]=ff(x-1)+ff(x-2);
}
int main(){
    f[0]=0;
    f[1]=1;
    f[2]=1;
    for(int i=2;i<=10000;i++){
        cout<<ff(i+1)*ff(i-1)-ff(i)*ff(i)<<" ";
        if(i%40==0) cout<<endl;
    }
}

 

 我们发现奇数为-1 偶数为1

但是这样还是无法通过 数太大了

那怎么办呢 我们可以直接看末尾数字呀(小学生都知道!!!)

代码:

int main(){
    string s;
    cin>>s;
    int n=s.size();
//    cout<<n<<endl;
    int t=s[n-1];
    t-=48;
    if(t%2==0) cout<<1;
    else cout<<-1;
}

 G-Game

思路分析:

数论问题 分解质因数 如果因子的个数为偶数那么win

代码:

int main(){
    ll n;
    n=read();
    int num=0;
    if(n==1) cout<<"Nancy"<<endl;
    else {
        for(int i=2;i<=n;i++){
            while (n%i==0) {
                n/=i;
                num++;
            }
        }
        num&1?cout<<"Nancy":cout<<"Johnson"<<endl;
    }
}

H- ”Happy New Year!“

思路分析:

智障题!!!

I-I love you 

思路分析:

一个简单的dp

代码:

const ll mod=20010905;
int main()
{
    string s;
    cin>>s;
    int len=s.length();
    ll ans1=0,ans2=0,ans3=0,ans4=0,ans5=0,ans6=0,ans7=0,ans8=0;
    for(int i=0;i<len;i++){
        if(s[i]=='i' || s[i]=='I') ans1=(ans1+1)%mod;
        if (s[i]=='l' || s[i]=='L') ans2=(ans2+ans1)%mod;
        if (s[i]=='o' || s[i]=='O') ans3=(ans2+ans3)%mod;
        if (s[i]=='v' || s[i]=='V') ans4=(ans3+ans4)%mod;
        if (s[i]=='E' || s[i]=='e') ans5=(ans5+ans4)%mod;
        if (s[i]=='y' || s[i]=='Y')  ans6=(ans6+ans5)%mod;
        if (s[i]=='o' || s[i]=='O')  ans7=(ans7+ans6)%mod;
        if (s[i]=='u' || s[i]=='U') ans8=(ans8+ans7)%mod;
    }
    cout<<ans8%mod;
   return 0;
}

J-Jelly

思路分析:

就是一个三维迷宫问题 bfs就行

代码

const ll INF = (ll)0x3f3f3f3f3f3f3f, MAX = 9e18, MIN = -9e18;
const int N = 1e2+10, M = 2e6+10, mod = 1e9+7, inf = 0x3f3f3f;
char a[N][N][N]; 
bool vis[N][N][N];
int dx[] = {-1, 1, 0, 0, 0, 0};
int dy[] = {0, 0, 0, 1, 0, -1};
int dz[] = {0, 0, 1, 0, -1, 0};
ll n;
struct node
{
	int x, y, z, s;
};

int bfs()
{
	queue<node> q;
	q.push({1, 1, 1, 1});
	while(q.size())
	{
		node t = q.front();
		q.pop();
		if(t.x == n&&t.y == n&&t.z == n)
			return t.s;
		rep(i, 6)
		{
			int x = t.x+dx[i], y = t.y+dy[i], z = t.z+dz[i];
			if(x >= 1&&x <= n&&y >= 1&&y <= n&&z >= 1&&z <= n&&a[x][y][z] == '.'&&!vis[x][y][z])
				q.push({x, y, z, t.s+1}), vis[x][y][z] = 1;
		}
	}
	return -1;
}

int main()
{
	IOS;
	cin>>n;
	rep1(i, n)
		rep1(j, n)
			rep1(k, n)
				cin>>a[i][j][k];
	cout<<bfs()<<nl;
	
	AC;
} 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

郭晋龙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值