Codeforces Round #308 (Div. 2)

原创 2015年07月10日 09:32:21

A - Vanya and Table 每次都给出一个子矩阵并让+1,最后求矩阵内数之和

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n, x1, y1, x2, y2, s = 0;
    scanf("%d",&n);
    while( n-- )
    {
        scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
        s = s + (x2 - x1 + 1) * (y2 - y1 + 1);
    }
    printf("%d\n", s);
    return 0;
}

B - Vanya and Books 1~n的数里面有多少位。暴力模拟

#include <bits/stdc++.h>
using namespace std;

typedef long long lol;

int main() {
    lol n;
    while ( cin >> n ) {
        lol temp = 1000000000;
        lol cnt = 10;
        lol res = 0;
        while ( temp>0&&n>0 ) {
            if ( n-(temp-1)>0 ) {
                res += (n-(temp-1))*(cnt);
                n = temp - 1;
            }
            temp /= 10;
            -- cnt;
        }
        cout << res << endl;
    }
    return 0;
}

C - Vanya and Scales 给出w进制的秤和m重的东西,问能否用秤称出m重的东西。

m化成w进制的数,则表示成 p0 * w^0 + p1 * w^1 +  p2 * w^2.......px * w^x。取其中一项pc * w^c,若pc = w-1,则pc * w^c + w^c = w * w^(c+1),即若最开始m重的东西放在左边,w进制里面若有一项系数为w-1,即等价于在左边放一个 w^c重的秤砣,右边放一个 w^(c+1)的秤砣。其他情况下,pc系数为0或1表示右边放或不放,是满足的

int main()
{
    int dig[222], tot;
    ll m, w;
    while( ~scanf("%lld%lld", &w, &m) ) {
        memset( dig, 0, sizeof( dig ) );
        tot = 0;
        ll x = m;
        while( x ) {
            dig[tot++] = x % w;
            x /= w;
        }
        bool OK = 1;
        for( int i = 0; i < tot; ++i ) {
            if( dig[i] == 0 || dig[i] == 1 )
                continue;
            if( dig[i] >= w-1 ) {
                dig[i+1]++;
                tot++;
            }
            else {
                OK = 0;
                break;
            }
        }
        puts( OK? "YES" : "NO" );
    }
    return 0;
}

D - Vanya and Triangles 给出平面上n个点,问能组成多少个三角形。

枚举每个点出发别的点到他的斜率即可

const int N = 2020;

ll x[N], y[N];
ll n;
map <ll, ll> mp;
map <ll, ll> :: iterator it;

pair <ll, ll> f( int i, int j )
{
    pair <ll, ll> re;
    ll xx = x[i] - x[j], yy = y[i] - y[j];
    if( xx == 0 ) {
        re.first = 1LL*N, re.second = 1LL*N;
        return re;
    }
    if( yy == 0 ) {
        re.first = 1LL*0, re.second = 1LL*0;
        return re;
    }
    ll xxx = xx / abs(xx), yyy = yy / abs(yy);
    yyy *= xxx, xxx = 1;
    xx = abs(xx), yy = abs(yy);
    ll gcd = __gcd( xx, yy );
    re.first = xx / gcd * xxx, re.second = yy / gcd * yyy;
    return re;
}

int main()
{
    while( ~scanf("%lld", &n) ) {
        mp.clear();
        ll ans = n * (n-1) * (n-2) / 6, tmp = 0;
        for( int i = 1; i <= n; ++i )
            scanf("%lld %lld", &x[i], &y[i]);
        for( int i = 1; i <= n; ++i ) {
            mp.clear();
            for( int j = 1; j <= n; ++j ) {
                if( i == j )
                    continue;
                pair <ll, ll> c = f( i, j );
                ll xx = c.first, yy = c.second;
                mp[xx*N+yy]++;
            }
            for( it = mp.begin(); it != mp.end(); ++it ) {
                tmp += (it->second >= 2) ? ((it->second-1) * it->second / 2) :0;
            }
        }
        ans -= tmp / 3;
        printf("%lld\n", ans);
    }
    return 0;
}

 表达式加一对括号,求表达式的最大值

括号加在*旁边就行了,暴力模拟过去,由于*最多15,复杂度15*15*n

#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <iomanip>
#include <algorithm>

using namespace std;

#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
#define ls rt << 1
#define rs rt << 1 | 1
#define pi acos(-1.0)
#define eps 1e-8
#define asd puts("sdfsdfsdfsdfsdfsdf");
typedef long long ll;
///typedef __int64 LL;
const int inf = 0x3f3f3f3f;
const int N = 5050;

int p[20], pos;
char s[N];

int main()
{
    while( ~scanf("%s", s+1 ) ) {
        int len = strlen( s+1 );
        s[len+1] = '+';
        pos = 0, p[pos++] = 0;
        for( int i = 1; i <= len+1; ++i ) {
            if( s[i] == '*' )
                p[++pos] = i;
        }
        p[++pos] = len+1;
        ll ans = 0;
        if( pos == 2 ) {
            ans = s[1] - '0';
            for( int i = 2; i <= len+1; ++i ) {
                if( s[i] != '+' )
                    ans += s[i] - '0';
            }
            printf("%lld\n", ans);
            continue;
        }
        for( int i = 0; i < pos; ++i ) {
            for( int j = i; j <= pos; ++j ) {
                int l = p[i], r = p[j];
                ll x = 0, tmp = 1, op = 0;      //op = 0----+  op = 1 ----- *
                for( int k = 1; k <= l; ++k ) {
                    if( s[k] >= '0' && s[k] <= '9' ) {
                        if( op == 0 )
                            tmp = s[k] - '0';
                        else
                            tmp *= s[k] - '0';
                    }
                    else if( s[k] == '+' ) {
                        x += tmp;
                        op = 0;
                    }
                    else {
                        op = 1;
                    }
                }
                //printf("%d %d %lld %lld\n", l, r, x, tmp);
                ll y = 0, op1 = 0, tmp1 = 1;
                for( int k = l+1; k <= r; ++k ) {
                    if( s[k] >= '0' && s[k] <= '9' ) {
                        if( op1 == 0 )
                            tmp1 = s[k] - '0';
                        else
                            tmp1 *= s[k] - '0';
                    }
                    else if( s[k] == '+' ) {
                        y += tmp1;
                        op1 = 0;
                    }
                    else {
                        op1 = 1;
                    }
                }
                if( op1 == 1 )
                    y += tmp1;
                //printf("%d %d %lld %lld\n", l, r, y, tmp1);
                ll tmp2 = 1;
                int o = r+1;
                for( ; o <= len+1 && s[o] != '+'; ++o ) {
                    if( s[o] >= '0' && s[o] <= '9' )
                        tmp2 *= s[o]-'0';
                }
                //printf("%d %d %lld \n", l, r, tmp2);
                x += tmp * y * tmp2;
                op = 0, tmp = 0;
                for( int k = o+1; k <= len+1; ++k ) {
                    if( s[k] >= '0' && s[k] <= '9' ) {
                        if( op == 0 )
                            tmp = s[k] - '0';
                        else
                            tmp *= s[k] - '0';
                    }
                    else if( s[k] == '+' ) {
                        x += tmp;
                        op = 0;
                    }
                    else {
                        op = 1;
                    }
                }
                //printf("%lld\n\n", x);
                ans = max( ans, x );
            }
        }
        printf("%lld\n", ans);
    }
    return 0;
}

// 1+2*3+4


版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

Codeforces Round #308 (Div. 2) A、B

552A - Vanya and Table 这题没什么好说的了,题目读懂了直接模拟就可以了。#include #include #include #include using namesp...

Codeforces Round #308 (Div. 2) —— D (思维题)

D. Vanya and Triangles time limit per test 4 seconds memory limit per test 512 megabytes input...

E. Vanya and Brackets(Codeforces Round #308 (Div. 2))

E. Vanya and Brackets time limit per test 1 second memory limit per test 256 megabytes ...

A. Vanya and Table(Codeforces Round #308 (Div. 2))

A. Vanya and Table time limit per test 2 seconds memory limit per test 256 megabytes ...

Codeforces Round #308 (Div. 2) C. Vanya and Scales(数制转换)

http://codeforces.com/contest/552/problem/C 要用质量为w0,w1,…,w100的砝码各1个称出重量m,砝码可以放在天平左边也可以放在右边。问是否可以称出,...

D. Vanya and Triangles(Codeforces Round #308 (Div. 2))

D. Vanya and Triangles time limit per test 4 seconds memory limit per test 512 megabytes...

Codeforces Round #308 (Div. 2)

A. Vanya and Table 水题、求覆盖矩形面积和 #include #include #include #include using namespace std; #define...

Codeforces Round #308 (Div. 2)题解

第二天补的 并不都是自己写的 参考了别人的题解 感觉这次cf题意好懂 就是做起来嘛。。 毕竟我还太弱。。 只为落实 A. Vanya and Table time limit per te...
  • GKHack
  • GKHack
  • 2015-06-20 16:23
  • 1118

Codeforces Round #308 (Div. 2)

再次厚颜无耻地宣传一发:新博客http://shijieyywd.com/?p=99这次cf真是发挥的有点醉,下次有div1我都不敢做了。A. Vanya and Table给你n个矩形,问你面积之和...

Codeforces Round #308 (Div. 2) C. Vanya and Scales dfs

题目链接:http://codeforces.com/contest/552/problem/C题意:给你100个砝码,第i个砝码质量是w^i,然后问你能不能在有m的情况下,左边和右边都放砝码,使得这...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)