您的位置:首页 > 其它

Codeforces Round #310 (Div. 2)

2015-06-28 00:48 309 查看
A. Case of the Zeros and Ones

题目大意:

  给出一个只含0和1的字符串,当是0和1相邻的话,这两个字符就可以删除,问最后不能删除的字符有多少个?

解题思路:

  只需要分别统计出来0和1的个数,然后相减之后的绝对值就是答案。

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;

const int maxn = 200010;
const int INF = 0x3f3f3f3f;
int Fabs (int a, int b)
{
if (a > b)
return a - b;
return b - a;
}
int main ()
{
char str[maxn];
int n, a, b;
while (scanf ("%d", &n) != EOF)
{
a = b = 0;
scanf ("%s", str);
for (int i=0; i<n; i++)
{
if (str[i] == '0')
a ++;
else
b++;
}
printf ("%d\n", Fabs(a , b));
}
return 0;
}


B. Case of Fake Numbers

题目大意:

  一个序列有n个数,从1开始编号,每次对序列的操作是奇树为加一,偶数为减一,问经过有限次操作后能不能构成0,1,2,3,4·······n-1的序列。

解题思路:

  因为这个序列中的数都是在[0,n-1]区间内的数字,这个序列肯定经过n次数的操作之后会循环,

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int a[maxn], b[maxn];
int main ()
{
int n;
while (scanf ("%d", &n) != EOF)
{
int flag = 1;
for (int i=0; i<n; i++)
{
scanf ("%d", &a[i]);
if (i != a[i])
flag = 0;
}
for (int j=0; j<n&&!flag; j++)
{
flag = 1;
for (int i=0; i<n; i++)
{

if (i % 2 == 0)
a[i] = (a[i] + 1) % n;
else
a[i] = (a[i] + n - 1) % n;
if (a[i] != i)
flag = 0;
}
}
if (flag)
printf ("Yes\n");
else
printf ("No\n");
}
return 0;
}


C. Case of Matryoshkas

题目大意:

  有n个可爱美丽滴俄罗斯娃娃,编号从1开始,编号大的可以套在编号小的上面,因为她们爱可爱了,所以现在要把它们全部套在一起娶回家。

套娃娃的时候只能有两种操作:

  1:把单独的一个大娃娃套在一串或者一个娃娃外面。

  2:把单独的一个娃娃在一串娃娃的最外层取下来。

问最小多少次操作才能把娃娃娶回家?

解题思路:

  就是模拟,就是迷你。

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;

const int maxn = 100010;
const int INF = 0x3f3f3f3f;

int main ()
{
int n, m;
while (scanf ("%d %d", &n, &m) != EOF)
{
int sum = m - 1, num, ans, a, b, c;
while (m --)
{
scanf ("%d", &num);
scanf ("%d", &c);
a = c;
ans = 0;
for (int i=1; i<num; i++)
{
scanf ("%d", &b);
if (b > a + 1 && ans == 0)
ans = num - i;
a = b;
}
if (c != 1)//只有大的可以向小的上面一个一个套,记住哦,是一个一个,在这里wa的心真是塞塞的
ans = num - 1;
sum += ans * 2;
}
printf ("%d\n", sum);
}
return 0;
}
/*
9 3
3 7 8 9
3 1 2 3
3 4 5 6

*/


后面的题目本宝宝真的做不到啊,毕竟手残党,明天一定第一时间给大家补上,~~~~~~~~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: