Codeforces Round#308
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的更多相关文章
- 水题 Codeforces Round #308 (Div. 2) A. Vanya and Table
题目传送门 /* 水题:读懂题目就能做 */ #include <cstdio> #include <iostream> #include <algorithm> ...
- 数学 Codeforces Round #308 (Div. 2) B. Vanya and Books
题目传送门 /* 水题:求总数字个数,开long long竟然莫名其妙WA了几次,也没改啥又对了:) */ #include <cstdio> #include <iostream& ...
- 暴力/进制转换 Codeforces Round #308 (Div. 2) C. Vanya and Scales
题目传送门 /* 题意:问是否能用质量为w^0,w^1,...,w^100的砝码各1个称出重量m,砝码放左边或在右边 暴力/进制转换:假设可以称出,用w进制表示,每一位是0,1,w-1.w-1表示砝码 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #308 (Div. 2)
A. Vanya and Table Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows ...
- 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 ...
- 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 ...
随机推荐
- VC图形绘制双缓存的代码复用性讨论
在前文中已经讨论了如何实现界面绘制双缓存的问题,前文网址如下: http://www.2cto.com/kf/201111/112429.html 双缓存的主要思路是:先把图形绘制到内存DC中,然后再 ...
- Java实现敏感词过滤(转)
敏感词.文字过滤是一个网站必不可少的功能,如何设计一个好的.高效的过滤算法是非常有必要的.前段时间我一个朋友(马上毕业,接触编程不久)要我帮他看一个文字过滤的东西,它说检索效率非常慢.我把它程序拿过来 ...
- JavaFX学习之路:详细解释JavaFX架构和框架
JavaFX 2.0平台是基于Java技术的富client平台.它使应用程序开发人员更加easy的开发和部署跨平台的富互联网应用(RIA).JavaFX 2.0文档包括了JavaFX 2.0所提供的功 ...
- 贪心算法-找零钱(C#实现)
找零钱这个问题很清楚,无非就是始终拿可以取的最大面值来找,最后就使得张数最小了,这个实现是在假设各种面值足够多的情况下. 首先拖出一个界面来,最下面是一个listbox控件 对应的代码:问题比较简单, ...
- MySQL的Master/Slave群集安装和配置
本文介绍MySQL的Master/Slave群集安装和配置,版本号安装最新的稳定版GA 5.6.19. 为了支持有限HA.我们用Master/Slave读写简单孤立的集群.有限HA这是当Master不 ...
- poj 3270 更换使用
1.确定初始和目标状态. 明确.目标状态的排序状态. 2.得出置换群,.比如,数字是8 4 5 3 2 7,目标状态是2 3 4 5 7 8.能写为两个循环:(8 2 7)(4 3 5). 3.观察当 ...
- ZOJ 3794 Greedy Driver
两次SPFA 第一关找:从1没有出发点到另一个点的多少是留给油箱 把边反过来再找一遍:重每一个点到终点最少须要多少油 Greedy Driver Time Limit: 2 Seconds ...
- 解决com.ibatis.sqlmap.client.SqlMapException: There is no statement named in this SqlMap
com.ibatis.sqlmap.client.SqlMapException: There is no statement named in this SqlMap. 可能存在3种情况: 1.在x ...
- java中怎么终止一个线程的执行----个人学习心得
参考了一下两个网站的介绍: ①:http://blog.csdn.net/liuhanhan512/article/details/7077601 ②:http://www.blogjava.net/ ...
- POJ-1324-Holedox Moving(BFS)
Description During winter, the most hungry and severe time, Holedox sleeps in its lair. When spring ...