最近开始做codeforces上得题,感觉有以下几点:
1、俄罗斯式的英语真难懂啊!2、codeforces上得题目很不错,对于思路来说,有点的妙,甚至是一些简单的题 3、codeforces上很重视计算几何,这个方面我不是很强,而且,codeforces很注重数学和数学思想!
开始总结一下这几天的题吧
codeforces beta round #1A 简单题,不解释
codeforces beta round #2A A题都是不很难,10进制和26进制之间的转换,但是26进制中没有0的概念,得A是1,这个不是很难想
codeforces beta round #4A 有一个重w的西瓜,问能不能切成两块都是偶数重的西瓜? 当w=2不能,但是当w>2是偶数能,奇不能,没意思吧
codeforces beta round #82A 有这么一个队列,当队首的人出队之后,队尾将出现两个出队的人,题目有点意思;队伍初始化为5个人
数学吧,这个我用过,代码如下:
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int get(int n)
{
if(n <= 5) return n;
else return get( (n-4)/2 );
}
int main()
{
string re[] = { "", "Sheldon", "Leonard", "Penny", "Rajesh", "Howard"};
int n;
while(cin >> n)
{
cout << re[get(n)] << "\n";
}
}
codeforces beta round #A 做完这个题之后的第一感觉是,让一个水题给虐了,首先是题目的意思看不懂。看了好多遍也没有看懂最后谁赢!以至于代码敲了好几遍!
最后虽然看懂了,但是也用了我很久的时间,有点浪费啊!这个题赢的规则,也有点别扭,就是最后的最高分,当有多个人时,赢的人为这些最高分的人中最先达到或者超过这个分数的人。
//让一个水题虐了!!!
#include <algorithm>
#include <string.h>
#include <stdio.h>
#include <iostream>
#include <map>
using namespace std;
map <string ,int> mapp;
map <string ,int> mapp2;
struct note
{
string name;
int score;
}data[1100];
int ma;
int main()
{
int n;
while(cin >> n)
{
ma = -100000000;
string re;
for(int i = 0;i < n;i++)
cin >> data[i].name >> data[i].score;
mapp.clear();
for(int i = 0;i < n;i++)
{
string name = data[i].name;
int score = data[i].score;
mapp[ name ] += score;
}
map <string ,int> ::iterator theIter;
for (theIter = mapp.begin(); theIter != mapp.end(); theIter ++){
ma = max(ma,theIter -> second);
}
mapp2.clear();
for(int i = 0;i < n;i++)
{
string name = data[i].name;
int score = data[i].score;
mapp2[ name ] += score;
if(mapp[ name ] == ma && mapp2[ name ] >= ma)
{
re = name;
break;
}
}
cout << re << "\n";
}
return 0;
}
codeforces beta round #2B 问题是求矩阵左上角到右下角的路径所有数字的乘的最后末尾的0的个数最少。首先很明显和2,5因子数有关。思路:两遍dp分别求出最少的2
和最少的5,这两个最少的一个就是答案。但是这个里面并没有考虑0的情况,考虑进去就管了。最后输出路径就行了,这个题思路是这样的没错,但是我还没
有a
codeforces beta round #3A 题目大意:棋盘上有两个点,始点和终点,可以8个方向走,问最短的路径是多少步,输出每一步的方向,这个题有一个博客说事广搜,我觉得用广搜就相当于杀鸡用牛刀,呵呵,这个直接输出就是了
//这个题的代码不是很好,见谅
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
int abs(int a)
{
return a > 0 ? a : 0-a;
}
string getR(int a,int b,int aa,int bb)
{
if(a == aa) return b < bb ? "U":"D";
if(b == bb) return a < aa ? "R":"L";
if(a > aa && b > bb) return "LD";
else if(a > aa && b < bb) return "LU";
else if(a < aa && b > bb) return "RD";
else if(a < aa && b < bb) return "RU";
}
int main()
{
int a,aa,b,bb;
char c[10];
gets(c);
a = c[0]-'a'; b = c[1]-'0';
gets(c);
aa = c[0]-'a';bb = c[1]-'0';
int re = abs(a-aa) + abs(b-bb) - min(abs(a-aa),abs(b-bb)) ;
printf("%d\n",re);
string s;
s = getR(a,b,aa,bb);
for(int i = 0;i < min(abs(a-aa),abs(b-bb));i++)
cout << s << "\n";
int t = min(abs(a-aa),abs(b-bb));
if(a > aa) a -= t;else a += t;
if(b > bb) b -= t;else b += t;
s = getR(a,b,aa,bb);
for(int i = 0;i < re-t;i++)
cout << s << "\n";
return 0;
}