A题,看样例就知道要求什么,   水过去

 #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <math.h>
using namespace std;
#pragma warning(disable:4996)
typedef long long LL;
const int INF = <<;
/* */
int vis[][];
int main()
{
int n, a, b, c, d;
scanf("%d", &n);
for (int i = ; i <= n; ++i)
{
scanf("%d%d%d%d", &a, &b, &c, &d);
for (int j = a; j <= c; ++j)
for (int k = b; k <= d; ++k)
vis[j][k]++;
}
int ans = ;
for (int i = ; i <= ; ++i)
for (int j = ; j <= ; ++j)
if (vis[i][j])
ans += vis[i][j];
printf("%d\n", ans);
return ;
}

B题 给定一个数字n, 问从1到n的数字的总位数之和,刚开始的时候想到了数位dp,后来发现并不用这样

位数为1的数有9个, 位数为2的数有90个,位数为3的数,有900个,依次类推。

所以对于给定数字n=123, 9*1 + 90 * 2, 然后算出位数为3的数字有多少个即可。

 #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <math.h>
using namespace std;
#pragma warning(disable:4996)
typedef __int64 LL;
const int INF = <<;
/* */ int main()
{
LL n;
scanf("%I64d", &n);
char str[];
LL m = ;
sprintf(str, "%I64d", n);
LL len = strlen(str);
LL ans = ;
LL t = ;
LL i = ;
for (i = ; i < len - ; ++i)
{
ans = ans + t * (i + );
t *= ;//位数为i+1的数字有多少个
m = m * ;
}
ans += (i+) * (n - m + );
printf("%I64d\n", ans);
return ;
}

C题 给定一个w和m,   那么我们就拥有w^0, w^1,w^2,w^3...w^100  g的砝码,

问称货物m,能不能使得天平两端平衡,(砝码可以加在两端)

刚开始的思路是  只要砝码相减的值是m或者m+1或者m-1

即 w(x-y) = m   ||  w(x-y) = m - 1  || w(x-y) = m + 1  就可以平衡           为什么+1 或者-1呢, 因为w^0是一个特殊的值

两边同除w --->  x-y = m/w || x-y = (m+1)/y || x-y = (m-1)/y

后来发现就算能整除,砝码可能凑不出(x-y), 所以问题就转为了, 砝码能不能凑出(x-y),

就变成了程序原来的问题,因为两边同除w,所以就变为w^0, w^1,w^2,w^3...w^99的砝码能不能使得x-y在天平上平衡

所以这是一个递归的问题,  只要x-y能够为1,那么砝码便能使得天平平衡(因为总是存在1g的砝码)

 #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <math.h>
using namespace std;
#pragma warning(disable:4996)
typedef long long LL;
const int INF = <<;
/* */
bool flag;
void dfs(int w, int m)
{
if (m == )
{
flag = true;
return;
}
if ((m - ) % w == )
dfs(w, (m - ) / w);
else if (m%w == )
dfs(w, m / w);
else if ((m + ) % w == )
dfs(w, (m + ) / w);
}
int main()
{
int w, m;
scanf("%d%d", &w, &m);
flag = false;
dfs(w, m);
if (flag)
puts("YES");
else
puts("NO");
return ;
}

D题,给定n个点,问能构成多少个三角形, 暴力居然可以过,  2000*2000*2000  可以在4s的时间内跑过

 #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <math.h>
using namespace std;
#pragma warning(disable:4996)
typedef long long LL;
const int INF = <<;
/*
给定n个点,问可以生成多少个三角形
*/
const int N = + ;
struct Point
{
int x, y;
bool operator<(const Point&rhs)const
{
if (x == rhs.x)
return y < rhs.y;
return x < rhs.x;
}
}a[N];
int main()
{
int n,i,j,k;
scanf("%d", &n);
for (i = ; i < n; ++i)
{
scanf("%d%d", &a[i].x, &a[i].y);
}
int ans = ;
for (i = ; i < n; ++i)
for (j = i + ; j < n; ++j)
for (k = j + ; k < n; ++k)
{
if (a[k].x>a[j].x && a[k].y > a[j].y)
{
ans += n - k;
break;
}
if (a[i].x != a[j].x || a[i].x != a[k].x || a[k].x != a[i].x)
{
if(a[i].y != a[j].y || a[i].y != a[k].y || a[k].y != a[i].y)
ans++;
}
}
printf("%d\n", ans);
return ;
}

Codeforces Round#308的更多相关文章

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

    题目传送门 /* 水题:读懂题目就能做 */ #include <cstdio> #include <iostream> #include <algorithm> ...

  2. 数学 Codeforces Round #308 (Div. 2) B. Vanya and Books

    题目传送门 /* 水题:求总数字个数,开long long竟然莫名其妙WA了几次,也没改啥又对了:) */ #include <cstdio> #include <iostream& ...

  3. 暴力/进制转换 Codeforces Round #308 (Div. 2) C. Vanya and Scales

    题目传送门 /* 题意:问是否能用质量为w^0,w^1,...,w^100的砝码各1个称出重量m,砝码放左边或在右边 暴力/进制转换:假设可以称出,用w进制表示,每一位是0,1,w-1.w-1表示砝码 ...

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

    D. Vanya and Triangles Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55 ...

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

    C. Vanya and Scales Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/552/p ...

  6. Codeforces Round #308 (Div. 2)B. Vanya and Books 数学

    B. Vanya and Books Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/552/pr ...

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

    A. Vanya and Table Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/552/pr ...

  8. Codeforces Round #308 (Div. 2)

    A. Vanya and Table   Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows ...

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

    C. Vanya and Scales time limit per test 1 second memory limit per test 256 megabytes input standard ...

  10. Codeforces Round #308 (Div. 2) A B C 水 数学

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

随机推荐

  1. Mysql InnoDB 是IOT表 锁基于索引

    </pre>Mysql InnoDB 是IOT表 锁基于索引<pre>

  2. 如何debug ruby

    how to debug ruby: 1. 第一种方法,直接使用ruby内建的debug在命令行调试,这个个gdb或者pdb的命令差不多. ruby -r debug yourubyfile.rb 2 ...

  3. Linux搭建Tomcat环境

    安装Tomcat 1)下载apache-tomcat-7.0.42.tar.gz        http://tomcat.apache.org/download-70.cgi 2)#tar -zxv ...

  4. 【夯实基础】Spring在ssh中的作用

    尊重版权:http://blog.csdn.net/qjlsharp/archive/2009/03/21/4013255.aspx 写的真不错. 在SSH框假中spring充当了管理容器的角色.我们 ...

  5. Python逐块读取大文件行数的代码 - 为程序员服务

    Python逐块读取大文件行数的代码 - 为程序员服务 python数文件行数最简单的方法是使用enumerate方法,但是如果文件很大的话,这个方法就有点慢了,我们可以逐块的读取文件的内容,然后按块 ...

  6. linux expect, spawn用法小记

    linux expect, spawn用法小记_IT民工_百度空间 linux expect, spawn用法小记 版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明http://sys ...

  7. 15个最好的HTML5前端响应式框架(2014)

    文中的多个框架基于SASS创建,SCSS是一种比LESS更简洁的样式表编程语言,它能够编绎成CSS,可复用CSS代码,声明变量,甚至是函数,类Ruby/Python的语法.參见: LESS vs SA ...

  8. hdu1695(莫比乌斯反演)

    传送门:GCD 题意:求[1,n],[1,m]gcd为k的对数. 分析:莫比乌斯入反演门题,gcd(x,y)==k等价于gcd(x/k,y/k)==1,求出[1,n][1,m]互质的对数,在减去[1, ...

  9. 基于CORS的geoserver同源访问策略

    这个问题理顺整个2天.终于攻克.记录下来. 1.下载文件 首先下载cors压缩包,解压,得到的是org/mortbay/servlets/CrossOriginFilter.class文件,把此文件拷 ...

  10. hdu 2451 Simple Addition Expression(数位DP )成败在于细节

    亚洲区域赛的题,简单的数位DP题,注重细节. 任何细节都有可能导致wa,所以没有绝对的水题. 把握好细节,此题便A. #include<stdio.h> __int64 getans(__ ...