数学 2016.2.18

1、UVa UVA 10790 How Many Points of Intersection?(多少个交点?)

#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    long long a, b;
    long long cases = 0;

    while (scanf("%lld%lld", &a,&b)!=EOF && !(a==0&&b==0)) {
        long long sum;
        sum = a*(a-1)*b*(b-1)/4;
        ++cases;
        printf("Case %lld: %lld\n", cases, sum);
    }
    return 0;
}

2、UVa 10719 Quotient Polynomial(多项式除法的商)

#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int k;
    int a[10010];
    int b[10010];

    while (cin>>k) {
        int count = 0;
        int i;
        char c;
        while (cin>>a[count]) {
            scanf("%c", &c);
            ++count;
            if (c == '\n') {
                break;
            }
        }
        b[0] = a[0];
        for (i=1; i<count; ++i) {
            b[i] = a[i] + k*b[i-1];
        }
        cout<<"q(x): ";
        for (i=0; i<count-2; ++i) {
            cout<<b[i]<<" ";
        }
        cout<<b[count-2]<<endl;
        cout<<"r = "<<b[count-1]<<endl;
        cout<<endl;
    }
    return 0;
}

3、UVa 10014 Simple calculations(简单计算)

#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
    int T;
    int n;
    double a0, anjia1;
    int i, j;
    double c[4000];
    double result;

    cout.setf(ios::fixed);

    while (cin>>T) {
        while (T--) {
            cin>>n;
            cin>>a0>>anjia1;
            double sum = 0;
            for (i=1; i<=n; ++i) {
                cin>>c[i];
                for (j=1; j<=i; ++j) {
                    sum += c[j];
                }
            }
            result = (n*a0 + anjia1 - 2*sum) / (n+1);
            cout<<setprecision(2)<<result<<endl;

            if (T > 0) {
                cout<<endl;
            }
        }
    }
    return 0;
}

4、HDU 2095 find your present (2)
题意:输入若干个数,输出出现次数为奇数的数

解题思路:
一、 对输入所有的数进行异或运算
二、 用C++的set
对每次输入在set中进行查找,没找到则插入,找到则删除

Problem Description
In the new year party, everybody will get a “special present”.Now it’s your turn to get your special present, a lot of presents now putting on the desk, and only one of them will be yours.Each present has a card number on it, and your present’s card number will be the one that different from all the others, and you can assume that only one number appear odd times.For example, there are 5 present, and their card numbers are 1, 2, 3, 2, 1.so your present will be the one with the card number of 3, because 3 is the number that different from all the others.

Input
The input file will consist of several cases.
Each case will be presented by an integer n (1<=n<1000000, and n is odd) at first. Following that, n positive integers will be given in a line, all integers will smaller than 2^31. These numbers indicate the card numbers of the presents.n = 0 ends the input.

Output
For each case, output an integer in a line, which is the card number of your present.

Sample Input

5
1 1 3 2 2
3
1 2 1
0

Sample Output

3
2

Hint

use scanf to avoid Time Limit Exceeded

#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int n;
    unsigned long long x, y;

    while(scanf("%d",&n)!=EOF && n!=0)
    {
        y = 0;
        while(n--)
        {
            scanf("%I64u", &x);
            y ^= x;
        }
        printf("%I64u\n", y);
    }
    return 0;
}
#include <iostream>
#include <set>
#include <cstdio>

using namespace std;

int main()
{
    int n;
    unsigned long long x;
    set <int> S;

    while(scanf("%d",&n)!=EOF && n!=0)
    {
        while(n--)
        {
            scanf("%I64u", &x);
            if(S.find(x) == S.end()) {
                S.insert(x);
            } else {
                S.erase(x);
            }
        }
        printf("%d\n",*S.begin());
        S.clear();
    }
    return 0;
}

5、CF Experimental Educational Round: D. Hexagons!
解题思路:
由等差数列的求和公式计算出表达式

这里写图片描述

After a probationary period in the game development company of IT City Petya was included in a group of the programmers that develops a new turn-based strategy game resembling the well known “Heroes of Might & Magic”. A part of the game is turn-based fights of big squadrons of enemies on infinite fields where every cell is in form of a hexagon.

Some of magic effects are able to affect several field cells at once, cells that are situated not farther than n cells away from the cell in which the effect was applied. The distance between cells is the minimum number of cell border crosses on a path from one cell to another.

It is easy to see that the number of cells affected by a magic effect grows rapidly when n increases, so it can adversely affect the game performance. That’s why Petya decided to write a program that can, given n, determine the number of cells that should be repainted after effect application, so that game designers can balance scale of the effects and the game performance. Help him to do it. Find the number of hexagons situated not farther than n cells away from a given cell.
这里写图片描述
Input

The only line of the input contains one integer n (0 ≤ n ≤ 109).
Output

Output one integer — the number of hexagons situated not farther than n cells away from a given cell.
Examples
Input

2

Output

19

#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    long long n;

    while (cin>>n) {
        long long result = 1 + (n)*6 + (n)*(n-1)*3;
        cout<<result<<endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值