A Alphabet Cookies(水)
题目大意:输入2个字符串,能否在第一个字符串中找到字符组成第二个字符串,字符串全大写
解题思路:水~
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <list>
#include <set>
using namespace std;
const int maxn = 100+10;
char s[maxn],s1[maxn];
int cnt[30];
int main()
{
int n;
while(scanf("%d",&n) != EOF)
{
getchar();
scanf("%s",s);
int l1 = strlen(s);
memset(cnt,0,sizeof(cnt));
for(int i = 0; i < l1; i++)
{
cnt[s[i]-'A']++;
}
scanf("%s",s1);
int l2 = strlen(s1);
int flag = 0;
for(int i = 0; i < l2; i++)
{
if(cnt[s1[i]-'A'] > 0)
cnt[s1[i]-'A']--;
else
{
flag = 1;
break;
}
}
if(flag)
puts("No");
else
puts("Yes");
}
return 0;
}
B Sequential game(水)
题目大意:题目给出一串01串,下一个字符跟最右边的相同则加到串上,否则之前的全变成相反的,该字符加到末尾,求最后有多少个0多少个1
解题思路:水~规则总能使得每一笔之后所有的位全相等,只需要看最后一位的情况,是1则全是1,否则全为0
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <list>
#include <set>
using namespace std;
const int maxn = 10000+10;
char s[maxn];
int main()
{
int n;
while(scanf("%s",&s) != EOF)
{
int l = strlen(s);
char c = s[l-1];
if(c == '0')
printf("%d 0\n",l);
else
printf("0 %d\n",l);
}
return 0;
}
C Programming Contest Ranking(模拟)
题目大意:一道算acm排名的题,输入n表示参赛队伍数,m表示题目总数,以下是每个队的情况,按排名输出排名(排名相同按权重值输出),队名,每个队解决的题数,总耗时,权重值(该队解决提的权相加,floor(权为总队伍数/该题解决人数)
解题思路:模拟算,注意输出格式
E Similar Word
题目大意:给出2行字符串,问2个字符串是否相似,相似为字符串1经过顺时针可以得到2,且若2字符串一开始相等则不符合
解题思路:将字符串再复制一遍即可将题意转换为在字符串1中查找字符串2
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <list>
#include <set>
using namespace std;
const int maxn = 100000+10;
char a[maxn],b[maxn],c[2*maxn];
int main()
{
while(scanf("%s",a) != EOF)
{
scanf("%s",b);
int la = strlen(a);
int lb = strlen(b);
if(la!=lb)
{
puts("no");
continue;
}
int k = 0;
for(int i = 1; i < la; i++)
c[k++] = a[i];
for(int i = 0; i < la-1; i++)
c[k++] = a[i];
if(strstr(c,b))
puts("yes");
else
puts("no");
}
return 0;
}
F Post office(中位数)
题目大意:给出n个位置在一条直线上,求在i位置和j位置之间修一个站,使得到i和j之间的距离之和最小
解题思路:求中位数
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <list>
#include <set>
using namespace std;
const int maxn = 1000+10;
int a[maxn];
int main()
{
int n,q;
while(scanf("%d",&n) != EOF)
{
if(!n) break;
for(int i = 1; i <= n; i++)
{
scanf("%d",&a[i]);
}
scanf("%d",&q);
int s,t;
for(int i = 1; i <= q; i++)
{
scanf("%d%d",&s,&t);
double tmp = a[(s+t)/2];
double ans = 0.0;
for(int j = s; j <= t; j++)
{
ans += fabs(double(a[j]-tmp));
}
printf("%.0lf\n",ans);
}
}
return 0;
}
G Lucky Boy(差乘二分+博弈)
题目大意:给出n个点(n<1000),2个人轮流移动点,一次可以移动1个点或者同一直线上的点,一个人能赢的条件为能同时移动超过2个点或将所有点移完
解题思路:判断初始状态的点是否有3点共线,即判断向量的差乘是否为0。,因为点很多、、要用二分,若初始状态没有3点共线,则判断n是否能被3整除
H Car race game (归并排序求逆序对)
题目大意:有n辆车(n<100000)排成一条直线,给出每辆车的位置和时间,求能完成多少次超过事件,若起点相同,也算一次超过事件
解题思路:将n辆车先按位置从小到大排序,再按速度从大到小排序,排序之后求逆序对,注意处理时间和速度都相同的点
I Jiulianhuan(推公式)
题目大意:求解开n连环所需的最小步数
解题思路:公式f(1)=1,f(2)=2,f(n)=2*f(n-2)+f(n-1)+1,注意时间和内存
J The minimum square sum(数论结论)
题目大意:给出素数p,求最小的x^2+y^2,使得x^2+y^2=0 (mod p)
解题思路:结论p=4k+3则没有平方和会等于P,否则就有,且当x==y时有最小值
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <list>
#include <set>
using namespace std;
int main()
{
long long p;
while (cin>>p)
{
if (p==2) puts("2");
else if((p-3)%4==0) cout<<2*p*p << endl;
else cout <<p<< endl;
}
return 0;
}