3 月 16 日 课 堂 总 结 与 归 纳

1 . A. Bus Game

题目:Problem - 115A - Codeforcesicon-default.png?t=M276https://codeforces.com/problemset/problem/115/A

代码:

#include<bits/stdc++.h>
using namespace std;
int m,dp;
vector<int>g[2005];
int vs[2005],a[2005];
void ds(int x)
{
    for(int i=0;i<g[x].size();i++)
    {
        int u=g[x][i];
        if(!vs[u])
        {
            vs[u]=1;
            dp++;
            ds(u);
            if(dp>m) m=dp;
            dp--;
        }
    }
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]==-1) continue;
        g[a[i]].push_back(i);
    }
    m=1;
	dp=1;
    memset(vs,0,sizeof vs);
    for(int i=1;i<=n;i++)
    {
        if(a[i]==-1&&!vs[i])
        {
            vs[i]=1;
            ds(i);
        }
    }
    cout<<m<<endl;
}

2 .A. Measuring Lengths in Baden

题目:Problem - 125A - Codeforcesicon-default.png?t=M276https://codeforces.com/problemset/problem/125/A

代码:

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b;
    cin>>n;
    a = n/36;
    b = (n-36*a)/3;
    if(n-36*a-3*b == 2) 
	{
        b++;
        if(b==12) 
		{
            a++;
            b=0;
        }
    }
    cout<<a<<' '<<b;
}

3 .A. Prime Permutation 

题目:Problem - 123A - Codeforcesicon-default.png?t=M276https://codeforces.com/problemset/problem/123/A代码:

#include <bits/stdc++.h>
int main()
{
    int n,a,b;
    cin>>n;
    a=n/36;
    b=(n-36*a)/3;
    if(n-36*a-3*b == 2) 
	{
        b++;
        if(b==12) 
		{
            a++;
            b=0;
        }
    }
    cout<<a<<b;
}

4 .A. Magical Array 

题目:Problem - 83A - Codeforcesicon-default.png?t=M276https://codeforces.com/problemset/problem/83/A代码:

#include<bits/stdc++.h>
using namespace std;
int n,a[100007];
long long ans,cnt=1;
int main() 
{
	cin>>n>>a[1];
	for(int i = 2; i <= n; ++i) 
	{
		cin>>a[i];
		if(a[i]==a[i-1]) cnt++;
		else 
		{
			ans+=cnt*(cnt+1)/2;
			cnt=1;
		}
	}
	ans+=cnt*(cnt+1)/2;
	cout<<ans;
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值