codeforce #164 div2
这次CF还是老样子,以我的水平只能做做水题,不过手速比前几次快了些......希望以后越来越快^_^
A题:看完啰嗦的题意就清楚了,两个循环,统计主队服装与客队服装的相同数......
[cpp]
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int n;
int home[50],away[50];
int main()
{
while(cin >> n)
{
for(int i=0; i<n; i++)
{
cin >> home[i] >> away[i];
}
int cnt = 0;
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
{
if(j != i && home[i] == away[j])
{
cnt++;
}
}
}
cout << cnt << endl;
}
return 0;
}
B题:一串密码,问最多需要按多少次按钮才能猜对。如果猜对当前一位,则继续;如果猜错,则回到初始位置。
When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequence), or all pressed buttons return to the initial position. When all buttons are pressed into the lock at once, the lock opens.
列几个简单的例子就找到规律了
[cpp]
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
int n;
while(cin >> n)
{
int sum = 0;
for(int i=1; i<=n; i++)
{
sum += i * (n-i);
}
sum += n;
cout <<sum <<endl;
}
return 0;
}
C题:在一个给定长宽的平面中,找到最长的整数点序列,使得任意两个点之间距离不为整数。
两个整数点最短的非整数距离为根号2,横纵坐标相差1。这样依次找出的点一定符合要求。
[cpp]
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int n, m;
int main()
{
while(cin >> n >> m)
{
int k = min(n,m)+1;
cout <<k <<endl;
for(int i=0; i<=k-1; i++)
{
cout <<i <<' ' << k-i-1 <<endl;
}
}
return 0;
}
补充:软件开发 , C++ ,