1 . A. Bus Game
题目:Problem - 115A - Codeforceshttps://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 - Codeforceshttps://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 - Codeforceshttps://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 - Codeforceshttps://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;
}