HDU 5284 - wyh2000 and a string problem
思路:先把相邻超过两个的v全部改为w。
然后这个问题就转化为了一个串是否能通过删除某些字符变成另一个子串了。
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <ctype.h>
#include <iostream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <assert.h>
#include <time.h>
#include <sstream>
typedef long long LL;
const int INF = 500000001;
const double EPS = 1e-9;
const double PI = acos(-1.0);
using namespace std;
char ch[3145766], c[100] = "wyh";
int main()
{
#ifdef _Te3st
freopen("test0.in", "r", stdin);
freopen("test0.out", "w", stdout);
srand(time(NULL));
#endif
int T;
scanf("%d", &T);
while(T--)
{
scanf("%s", ch);
int len = strlen(ch);
for(int i = 0; i < len; i++)
{
int en = i;
if(ch[i] == 'v')
{
for(int j = i; j < len; j++)
{
if(ch[j] == 'v') en = j;
else break;
}
}
if(en >= i + 1)
{
for(int j = i; j <= en; j++)
{
// puts("work");
ch[j] = 'w';
}
}
i = en;
}
int cnt = 0;
for(int i = 0; i < len; i++)
{
if(ch[i] == c[cnt])
{
++cnt;
}
if(cnt == 3) break;
}
if(cnt == 3)
{
puts("Yes");
}
else
{
puts("No");
}
}
return 0;
}
HDU 5285 - wyh2000 and pupil
思路:判断给定的所有边是否能构成二分图,利用深搜染色,就能求出。
比赛的时候读错题目了,以为每个集合里面要至少两个人认识的人呢。。
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <ctype.h>
#include <iostream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <assert.h>
#include <time.h>
#include <sstream>
typedef long long LL;
const int INF = 500000001;
const double EPS = 1e-9;
const double PI = acos(-1.0);
using namespace std;
int n, m;
vector<int> v[100005];
int vis[100005], ccc[100005];
int tmp[100005];
int cnt, cnt2;
int t1, t2;
bool flag;
void dfs(int i, int w, int last)
{
int sz = v[i].size();
for(int j = 0; j < sz; j++)
{
if(vis[v[i][j]])
{
vis[v[i][j]] = 0;
if(w == 1) ++t1;
else ++t2;
tmp[v[i][j]] = 1 - w;
dfs(v[i][j], 1 - w, i);
}
else
{
if(last != v[i][j] && w == tmp[v[i][j]])
{
flag = false;
}
}
}
}
int main()
{
#ifdef _Te3st
freopen("test0.in", "r", stdin);
freopen("test0.out", "w", stdout);
srand(time(NULL));
#endif
int T;
scanf("%d", &T);
while(T--)
{
memset(vis, 0, sizeof(vis));
scanf("%d %d", &n, &m);
if(n == 0 && m == 0)
{
puts("Poor wyh");
continue;
}
else if(m == 0)
{
if(n > 1) printf("%d %d\n", n - 1, 1);
else puts("Poor wyh");
continue;
}
for(int i = 0; i < m; i++)
{
int x, y;
scanf("%d %d", &x, &y);
vis[x] = vis[y] = 1;
v[x].push_back(y);
v[y].push_back(x);
}
flag = true;
cnt = 0;
cnt2 = 0;
for(int i = 1; i <= n; i++)
{
t1 = 0;
t2 = 0;
if(flag && vis[i])
{
vis[i] = 0;
tmp[i] = 0;
t1++;
dfs(i, 0, 0);
cnt += max(t1, t2);
cnt2 += min(t1, t2);
}
}
int tmp = n - cnt2 - cnt;
cnt += tmp;
if(flag)
{
printf("%d %d\n", cnt, cnt2);
}
else
{
puts("Poor wyh");
}
for(int i = 1; i <= n; i++)
{
v[i].clear();
}
}
return 0;
}