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. 关于jquery文件上传插件 uploadify 3.1的使用

    要使用uplaodify3.1,自然要下载相应的包,下载地址http://www.uploadify.com/download/,这里有两种包,一个是基于flash,免费的,一个是基于html5,需要 ...

  2. 打开asp出现An error occurred on the server when processing the URL

    分享到:   2013-01-21 15:38   提问者采纳   方法一 以管理员身份运行CMD,将目录定位到%windir%\system32\inetsrv\,然后执行appcmd set co ...

  3. 与众不同 windows phone (24) - Input(输入)之软键盘类型, XNA 方式启动软键盘, UIElement 的 Touch 相关事件, 触摸涂鸦

    原文:与众不同 windows phone (24) - Input(输入)之软键盘类型, XNA 方式启动软键盘, UIElement 的 Touch 相关事件, 触摸涂鸦 [索引页][源码下载] ...

  4. Java网络编程-对象编解码方案、优劣对照

    书籍推荐:   实例代码 :http://download.csdn.net/detail/jiangtao_st/7677503 watermark/2/text/aHR0cDovL2Jsb2cuY ...

  5. [Android学习笔记]LinearLayout布局,剩余空间的使用

    转自:http://segmentfault.com/q/1010000000095725 如果使得一个View占用其父View的剩余空间? 答案是使用:android:layout_weight = ...

  6. [C++]Hello C++

    最先进项目中需要用到C++做开发,所以开始学习C++,典型的眼高手低,刚开始觉得还算上手,之后越学越觉得复杂. 相比C#,C++确实需要开发者投入更多的精力去设计与维护. 以下是最近对C++开发的一些 ...

  7. Android内存管理

    首先Android理机制相当复杂.想要讲清楚比較困难.其次对于绝大多数用户来说.仅仅关心内存够不够用,至于内存怎样管理的这样的技术细节,不是用户须要去考虑的,写这样一个专题有没有意义?毕竟我们是用手机 ...

  8. STL__queue_的应用

    转:http://hi.baidu.com/xiaotiandm/item/bda34511cf9e99098fbde41a 调用的时候要有头文件: #include<stdlib.h> ...

  9. 改动file header (測)

    --改动file header ------------------------------------------------------------------------- cd $ORACLE ...

  10. 每天一点儿java-button

    <pre name="code" class="java">import java.awt.*; import java.awt.event.*; ...