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. vc中改变对话框的背景色

    ---- 笔者曾在<软件报>2000年第5期中讨论过如何改变控件的颜色,但还有相当一部分的读者来信提问:一个基于对话框的MFC AppWizard应用程序中,如何改变对话框的背景颜色呢?对 ...

  2. Missing artifact net.sf.json-lib:json-lib:jar:2.2.3:compile

    json-lib是需要区分jdk版本的,pom.xml中的配置应加上<classifier>标签,如用jdk15: <dependency> <groupId>ne ...

  3. li里的a标签浮动了,为什么li本身也浮动了?

    <ul> <li><a href="#"></a></li> <li><a href="#& ...

  4. [Android学习笔记]LayoutParams的使用

    LayoutParams的使用: 什么时候会用到此对象?动态布局,动态向ViewGroup中添加子view时,为子view设置此对象,目的是告诉父容器以何种方式呈现此子view LayoutParam ...

  5. Struts ActionForm简单理解

    要想明确struts的控制流程以及它核心API的实现原理(比方 Action/DispatchAction/ActionForm的实现原理),玩转struts1.2的关键就是可以玩转 ActionFo ...

  6. STL__queue_的应用

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

  7. Linux SSH常用总结(转)

    一.连接到远程主机 格式: ssh name@remoteserver 例如: ssh ickes@192.168.27.211 二.连接到远程主机指定的端口 格式: ssh name@remotes ...

  8. 常见问题(FAQ) | VPNCUP

    常见问题(FAQ) | VPNCUP 常见问题(FAQ) 关于FAQ 新手开始 登录验证问题 为什么刚注册后,登录VPN服务器提示错误? 免费注册的用户有哪些限制? 为什么连接免费VPN后20分钟自动 ...

  9. Everything You Wanted to Know About Machine Learning

    Everything You Wanted to Know About Machine Learning 翻译了理解机器学习的10个重要的观点,增加了自己的理解.这些原则在大部分情况下或许是这样,可是 ...

  10. Selenium 2.0 WebDriver 自动化测试 使用教程 实例教程 API快速参考

    Selenium 2.0 WebDriver 自动化测试 使用教程 实例教程 API快速参考 //System.setProperty("webdriver.firefox.bin" ...