codeforce #164 div2

这次CF还是老样子,以我的水平只能做做水题,不过手速比前几次快了些......希望以后越来越快^_^


A题:看完啰嗦的题意就清楚了,两个循环,统计主队服装与客队服装的相同数......

#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.

列几个简单的例子就找到规律了


#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。这样依次找出的点一定符合要求。

#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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值