CF #308 (Div. 2)

原创 2015年07月08日 22:33:55

太久没有打代码了。。。感觉脑袋根本已经秀逗了。。最奇怪的是,我连题目都看不懂了。。(:зゝ∠)
嗯,要多练了。
A. Vanya and Table
题目大意就是给你n个矩阵,对于每个矩阵,给你两个角上的坐标,求所有格子被覆盖的次数的总和。
直接做就行,对于每次覆盖,我们计算有几个格子被覆盖,然后重复n次,总和就是答案。

#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<time.h>
#include<queue>
#include<stack>
#include<iterator>
#include<math.h>
#include<stdlib.h>
#include<limits.h>
#include<map>
//#define ONLINE_JUDGE
#define eps 1e-10
#define INF 0x7fffffff
#define inf 0x3f3f3f3f
#define FOR(i,a) for((i)=0;i<(a);(i)++)
#define MEM(a) (memset((a),0,sizeof(a)))
#define sfs(a) scanf("%s",a)
#define sf(a) scanf("%d",&a)
#define sfI(a) scanf("%I64d",&a)
#define pf(a) printf("%d\n",a)
#define pfI(a) printf("%I64d\n",a)
#define pfs(a) printf("%s\n",a)
#define sfd(a,b) scanf("%d%d",&a,&b)
#define sft(a,b,c)scanf("%d%d%d",&a,&b,&c)
#define for1(i,a,b) for(int i=(a);i<b;i++)
#define for2(i,a,b) for(int i=(a);i<=b;i++)
#define for3(i,a,b)for(int i=(b);i>=a;i--)
#define MEM1(a) memset(a,0,sizeof(a))
#define MEM2(a) memset(a,-1,sizeof(a))
#define ll __int64
const double PI=acos(-1.0);
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
using namespace std;
int n,m;
int s;
#define N 2010
int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
//  freopen("out.txt","w",stdout);
#endif
    while(scanf("%d",&n)!=EOF){
        int ans=0;
        int x1,y1,x2,y2;
        while(n--){
            scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
            for(int i=x1;i<=x2;i++)
                for(int j=y1;j<=y2;j++)
                    ans++;
        }
            printf("%d\n",ans);
    }
return 0;
}

B. Vanya and Books
给你一个n,求1-n一共有几个数字,比如n=10,一共有11个数字(9+2)。这个好做,先预处理下,然后加上超过某个界限的个数。

#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<time.h>
#include<queue>
#include<stack>
#include<iterator>
#include<math.h>
#include<stdlib.h>
#include<limits.h>
#include<map>
//#define ONLINE_JUDGE
#define eps 1e-10
#define INF 0x7fffffff
#define inf 0x3f3f3f3f
#define FOR(i,a) for((i)=0;i<(a);(i)++)
#define MEM(a) (memset((a),0,sizeof(a)))
#define sfs(a) scanf("%s",a)
#define sf(a) scanf("%d",&a)
#define sfI(a) scanf("%I64d",&a)
#define pf(a) printf("%d\n",a)
#define pfI(a) printf("%I64d\n",a)
#define pfs(a) printf("%s\n",a)
#define sfd(a,b) scanf("%d%d",&a,&b)
#define sft(a,b,c)scanf("%d%d%d",&a,&b,&c)
#define for1(i,a,b) for(int i=(a);i<b;i++)
#define for2(i,a,b) for(int i=(a);i<=b;i++)
#define for3(i,a,b)for(int i=(b);i>=a;i--)
#define MEM1(a) memset(a,0,sizeof(a))
#define MEM2(a) memset(a,-1,sizeof(a))
#define ll __int64
const double PI=acos(-1.0);
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
using namespace std;
int n,m;
int s;
#define N 2010
ll f[20];
void Init(){
    int bas = 9;
    int mul = 1;
    for(int i=1;i<10;i++){
        f[i] = bas*mul;
        mul *= 10;
    }
}
ll getNum(int num){
    ll s=1;
    while(num--){
        s *= 10;
    }
    return s;
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
//  freopen("out.txt","w",stdout);
#endif
    Init();
    while(scanf("%d",&n)!=EOF){
        int sum=0;
        int tmp = n;
        while(tmp){
            sum++;
            tmp /= 10;
        }
//      printf("%d\n",sum);
        ll ans = 0;
        for(int i=1;i<sum;i++)
            ans += (f[i]*i);
        ans += (n-(getNum(sum-1))+1)*sum;
        printf("%I64d\n",ans);
    }
return 0;
}

C. Vanya and Scales
感觉这道题目不太理解。。看了别人的思路。就是有100个砝码,重量分别为w^0,w^1,w^2…..w^100,然后有个物品,重量为m,然后有一个天平,物品放在左边,砝码既可以放在左边,也可以放在右边,问你能否使得天平平衡。
可以用进制思想来考虑,对于一个m,如果它符合题目条件,那么它就可以用w进制来表示,即 m=A0*w^0+A1*w^1+A2*w^2……..+A100*w^100.
对于Ai,我们有三种取值,1.Ai=0,就是不用该砝码,2.Ai=1,使用该砝码,3.Ai=w-1,就是使得该砝码放在物品一侧,也就是放在天平左边。 第三种其实没怎么很理解。。Ai*w^i=(w-1)w^i=w(i+1)-w^i,右边做减法,相当于左边做加法。(:зゝ∠),做的时候我们边取余边做除法,如果余数为0,1或者w-1,则合法,注意当等于w-1时,因为右边除了后有一个w-1因子,这个是不合法的,所以我们在等式左边,也即是m,加上一个1。

#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<time.h>
#include<queue>
#include<stack>
#include<iterator>
#include<math.h>
#include<stdlib.h>
#include<limits.h>
#include<map>
//#define ONLINE_JUDGE
#define eps 1e-10
#define INF 0x7fffffff
#define inf 0x3f3f3f3f
#define FOR(i,a) for((i)=0;i<(a);(i)++)
#define MEM(a) (memset((a),0,sizeof(a)))
#define sfs(a) scanf("%s",a)
#define sf(a) scanf("%d",&a)
#define sfI(a) scanf("%I64d",&a)
#define pf(a) printf("%d\n",a)
#define pfI(a) printf("%I64d\n",a)
#define pfs(a) printf("%s\n",a)
#define sfd(a,b) scanf("%d%d",&a,&b)
#define sft(a,b,c)scanf("%d%d%d",&a,&b,&c)
#define for1(i,a,b) for(int i=(a);i<b;i++)
#define for2(i,a,b) for(int i=(a);i<=b;i++)
#define for3(i,a,b)for(int i=(b);i>=a;i--)
#define MEM1(a) memset(a,0,sizeof(a))
#define MEM2(a) memset(a,-1,sizeof(a))
#define ll __int64
const double PI=acos(-1.0);
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
using namespace std;
int n,m;
int s;
#define N 2010
int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
//  freopen("out.txt","w",stdout);
#endif
    int w;
    while(scanf("%d%d",&w,&m)!=EOF){
        int flag = 1;
        while(m){
            int tmp = m%w;
            m /= w;
            if(tmp == 0)
                continue;
            else if(tmp == 1)
                continue;
            else if(tmp == w-1)
                m++;
            else{
                flag = 0;
                break;
            }
        }
        if(flag)
            printf("YES\n");
        else
            printf("NO\n");
    }
return 0;
}

D. Vanya and Triangles
题意为给你n个点,问能组成几个面积不为0的三角形。。。
这个好像用暴力就行,枚举三个点,看能否共线,不共线就能组成面积不为0的三角形。

#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<time.h>
#include<queue>
#include<stack>
#include<iterator>
#include<math.h>
#include<stdlib.h>
#include<limits.h>
#include<map>
//#define ONLINE_JUDGE
#define eps 1e-10
#define INF 0x7fffffff
#define inf 0x3f3f3f3f
#define FOR(i,a) for((i)=0;i<(a);(i)++)
#define MEM(a) (memset((a),0,sizeof(a)))
#define sfs(a) scanf("%s",a)
#define sf(a) scanf("%d",&a)
#define sfI(a) scanf("%I64d",&a)
#define pf(a) printf("%d\n",a)
#define pfI(a) printf("%I64d\n",a)
#define pfs(a) printf("%s\n",a)
#define sfd(a,b) scanf("%d%d",&a,&b)
#define sft(a,b,c)scanf("%d%d%d",&a,&b,&c)
#define for1(i,a,b) for(int i=(a);i<b;i++)
#define for2(i,a,b) for(int i=(a);i<=b;i++)
#define for3(i,a,b)for(int i=(b);i>=a;i--)
#define MEM1(a) memset(a,0,sizeof(a))
#define MEM2(a) memset(a,-1,sizeof(a))
#define ll __int64
const double PI=acos(-1.0);
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
using namespace std;
int n,m;
int s;
#define N 2010
struct Point{
     int x,y;
     friend int operator *(Point A,Point B){return (A.x*B.y)-(A.y*B.x);}
     friend Point operator -(Point A,Point B){Point C;C.x=A.x-B.x;C.y=A.y-B.y;return C;}
}a[N];
int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
//  freopen("out.txt","w",stdout);
#endif
    int w;
    while(scanf("%d",&n)!=EOF){
        for(int i=0;i<n;i++)
            scanf("%d%d",&a[i].x,&a[i].y);
        int ans=0;
        for(int i=0;i<n;i++)
            for(int j=i+1;j<n;j++)
                for(int k=j+1;k<n;k++)
                    if((a[i]-a[j])*(a[j]-a[k])) ans++;  //不共线
        printf("%d\n",ans);
    }
return 0;
}

CF #308 Div.2 C题 Vanya and Scales 解题报告

原题: Vanya has a scales for weighing loads and weights of masses w0, w1, w2, ..., w100 grams where w...

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

题目链接:http://codeforces.com/contest/552/problem/C题意:给你100个砝码,第i个砝码质量是w^i,然后问你能不能在有m的情况下,左边和右边都放砝码,使得这...
  • yxg_123
  • yxg_123
  • 2017年02月26日 23:52
  • 77

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

CF题解DIV2

  • 2012年07月09日 14:38
  • 2KB
  • 下载

cf #308 E. Vanya and Brackets (暴力枚举)

题目:http://codeforces.com/contest/552/problem/E 题意:给你一个只有+和*的表达式,让你添加一对括号使得表达式的值最大。其中*号最多15个。 分析:明显...
  • w20810
  • w20810
  • 2015年12月27日 17:41
  • 279
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:CF #308 (Div. 2)
举报原因:
原因补充:

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