SDUT 2012春季ACM内部测试赛5

http://acm.sdut.edu.cn/web/contest_show.php?contest_id=1097

A题:(字符串问题)就是给定字典。然后查找错误。分三种情况

1:One letter is missing (e.g., letter is written leter)or too much (e.g., letter is writtenlettter).

2:One letter is wrong (e.g., letter is written ketter)

3:The order of two adjacent letters is wrong (e.g., letter is written lettre)

然后判断。。之前做过类似的一道题目,1Y..比赛时,队长负责的题目,也是果断1Y..厉害。

View Code
#include <iostream>
#include <cstdio>
#include <cstring>
#include <time.h>
#define maxn 10007
using namespace std;

char str[maxn][107];

bool isok(char *s1,char *s2)
{
//printf("%s %s\n",s1,s2);
int len1 = strlen(s1);
int len2 = strlen(s2);
int i,j;
char h1[107] = {'0'};
char h2[107] = {'0'};
//相等时
if (len1 == len2)
{
int l = 0;
for (i = 0; i < len1; ++i)
{
if (s1[i] != s2[i])
{
h1[l] = s1[i];
h2[l] = s2[i];
l++;
}
}
if (l == 1)//写错一个字母
return true;
else if (l == 2)//两个字母互换了位置
{
if (h1[0] == h2[1] && h1[1] == h2[0])
return true;
else
return false;
}
else return false;
}
//len2<len1少写字母了
else if (len1 == len2 + 1)
{
i = 0; j = 0;
while (i < len1 && s1[i] == s2[j] && j < len2)
{
i++; j++;
}
i++;
while (i < len1 && j <len2)
{
if (s1[i] != s2[j])
return false;
i++; j++;
}
return true;
}
//多写字母了
else if (len1 + 1 == len2)
{
i = 0; j = 0;
while (j < len2 && s1[i] == s2[j] && i < len1)
{
i++; j++;
}
j++;
while (i < len1 && j <len2)
{
if (s1[i] != s2[j])
return false;
i++; j++;
}
return true;
}
return false;
}
int main()
{
//freopen("d.txt","r",stdin);
int n,i,q;
char ch[107];
scanf("%d",&n);
for (i =0; i < n; ++i)
scanf("%s",str[i]);
//for (i =0; i < n; ++i)
//printf(">>%s\n",str[i]);
scanf("%d",&q);
while (q--)
{
scanf("%s",ch);
//printf(">>%s\n",ch);
bool flag = false;
//在字典中
for (i = 0; i < n; ++i)
{
if (!strcmp(str[i],ch))
{
flag = true;
break;
}
}
if (flag)
{
printf("%s is correct\n",ch);
continue;
}
//是否是拼写错误
for (i = 0; i < n; ++i)
{
if (isok(str[i],ch))
{
flag = true;
printf("%s is a misspelling of %s\n",ch,str[i]);
break;
}
}
//否则
if (!flag)
{
printf("%s is unknown\n",ch);
}
}
return 0;
}

F:果断的奇葩数据啊。。。。。。自己用hash挂链处理的哈希冲突。。。才开始使用的动态new开的内存。果断tle最后换成静态分配内存之后就A了。。。。

View Code
#include <iostream>
#include <cstdio>
#include <cstring>
#include <time.h>
#define maxn 1000007
using namespace std;

struct node
{
int num;
int val;
node *next;
}*p[maxn];
node H[maxn];
int pos;
int n,ct,a,b;

bool isok(int x,int y)
{
node *t;
bool flag = false;
for (t = p[x]; t != NULL; t = t->next)
{
if (t->num == y)
{
t->val++;
if (t->val == 2) ct++;
//printf(">>%d %d\n",t->num,t->val);
if (t->val == 3) return false;//遇到两次的直接跳出
flag = true;
break;
}
}
//puts("DDDD");
if (!flag)
{
node *q;
q = &H[pos++];//静态分配内存,果断能过。。动态tle
q->num = y; q->val = 1;
q->next = p[x];
p[x] = q;
}
return true;
}
int main()
{
//freopen("d.txt","r",stdin);
//int s = clock();
while (~scanf("%d",&n))
{
if (!n) break;
pos = 0;
memset(p,0,sizeof(p));
ct = 0;//记录出现两次的个数
scanf("%d%d",&a,&b);
int yu = b%n;
while (1)
{
int tmp = yu%maxn;
//printf(">>%d\n",tmp);
if (!isok(tmp,yu))
break;
__int64 l = yu%n;
yu = (((a%n)*((l*l)%n))%n + (b%n))%n;
}
printf("%d\n",n - ct);
}
//int e = clock();
//printf(">>%d\n",e-s);
return 0;
}

G: 这是我负责的一道题目,一个简单的贪心,我先是按+ - 数排序一下,同号的按序号从小到大排序,因为这样可以尽量让距离比较近的先进行交易。。开始没注意到long long 的提示果断的WA了一次。。后来von提醒了我一下才发现,改过了就A了。。

View Code
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define maxn 1000007
using namespace std;

struct node
{
int val;
int num;
}p[maxn];
int n;

int cmp(node a,node b)
{
if ((a.val > 0 && b.val >0) || (a.val < 0 && b.val < 0))
{
return a.num < b.num;
}
else
return a.val < b.val;
}
int main()
{
int i,j,pos;
while (cin>>n)
{
if (!n) break;
for (i = 0; i < n; ++i)
{
cin>>p[i].val;
p[i].num = i;
}
sort(p,p + n,cmp);//排序
for (i = 0; i < n; ++i)
{
if (p[i].val >= 0)
{
pos = i;break;
}
}
i = 0; j = pos;//从大于0的开始进行交易
long long ct = 0;
while (i < pos && j < n)
{
int tmp = p[j].val + p[i].val;
//printf(">>%d %d\n",tmp,ct);
if (tmp > 0)
{
long long m = abs(p[j].num - p[i].num) - 1;
ct = ct + (-p[i].val) + (m)*(-p[i].val);
p[j].val = tmp;
p[i].val = 0;
i++;
}
else if (tmp == 0)
{
long long m = abs(p[j].num - p[i].num) - 1;
ct = ct + (-p[i].val) + (m)*(-p[i].val);
p[j].val = p[i].val = 0;
i++; j++;
}
else if (tmp < 0)
{
long long m = abs(p[j].num - p[i].num) - 1;
ct = ct + (p[j].val) + (m)*(p[j].val);
p[j].val = 0;
p[i].val = tmp;
j++;
}
}
printf("%I64d\n",ct);
}
return 0;
}

F:本来该我负责的,可是我在G题上磨叽了很长时间,von就给做了。。。这道题好像是随机算法的问题,看了下随机算法做的可是做了之后是WA无语了。最后是分别判断没哥四边形,只要存在两个对角线和不相等。。肯定not homogeneous。。。

View Code
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define maxn 1007
using namespace std;

int a[maxn][maxn];
int main()
{
int n,i,j;

while (~scanf("%d",&n))
{
if (!n) break;
bool flag = false;
for (i = 0; i < n; ++i)
{
for (j = 0; j < n; ++j)
{
scanf("%d",&a[i][j]);
}
}
for (i = 0; i < n - 1; ++i)
{
for (j = 0; j < n - 1; ++j)
{
if (a[i][j] + a[i + 1][j + 1] != a[i][j + 1] + a[i + 1][j])
{
flag = true;
break;
}
}
if (flag) break;
}
if (flag) printf("not homogeneous\n");
else printf("homogeneous\n");
}
return 0;
}







你可能感兴趣的:(2012)