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. ActiveX控件的安全初始化和脚本操作 和 数字签名SIGN

    摘要:数字签名SIGN保证控件在下载时候的安全性.如果你的代码已经经过数字签名,即使用户IE的安全设置很高也能下载,安装并登记.但是在页面上初始化,或者用脚本运行这个控件,为了保证安全性,还需要进行M ...

  2. Cocos2d-x CCProgressTimer

    CCProgressTimer,创建使用这个节点可以大致实现两个作用的效果: 其一:在游戏中几乎大部分的游戏启动界面都是游戏加载画面,那么用到的一般是进度条提示加载进度,其使用的就是CCProgres ...

  3. Swift - 使用EventKit获取系统日历事件,添加事件

    通过EventKit可以对iOS日历事件进行读取,添加等操作.但网上找到的都是使用Objective-C来编写的. 下面提供一个Swift版的样例,演示如何添加一个事件以及获取所有的事件列表. 1 2 ...

  4. 如何在Android Studio上使用Github

    首先,登陆到Github上并创建一个新repository.在屏幕右上角,点击“+”标记,并且选择“New repository”. 现在完成这个表格以新建一个叫做testproject的新repos ...

  5. Java NIO实战之聊天室

    在工作之余花了两个星期看完了<Java NIO>.整体来说这本书把NIO写的非常具体,没有过多的废话,讲的都是重点,仅仅是翻译的中文版看的确实吃力.英文水平太低也没办法,总算也坚持看完了. ...

  6. 腾讯文学动作密集 疑为手Q发力移动阅读铺路

        移动互联网的门票之争并未结束,百度收购91无线,阿里投资新浪微博.UC浏览器,网易推易信.云音乐等等,都是互联网巨头争夺移动互联网门票的最佳案例.不过,上述任何巨头都不可忽视腾讯这个“狠角色” ...

  7. MongoDB查询命令具体解释

    1.查询全部记录 复制代码代码例如以下: db.userInfo.find(); 相当于:select* from userInfo; 默认每页显示20条记录,当显示不下的情况下,能够用it迭代命令查 ...

  8. codeforces 597B Restaurant

    题目链接:http://codeforces.com/contest/597/problem/B 题目分类:贪心 题目分析:经典的看节目问题(挑战程序设计page 40) 代码: #include&l ...

  9. java特权制度设计篇

    数据库表设计 1.1.1.   模块管理(jk_module) 项 类型 说明 id long 就是数据库记录idx号 name string 模块名称 orderid int 排序id  由小到大显 ...

  10. GNU C的使用

    基本语法 gcc [options] [filenames]  说明:  在gcc后面可以有多个编译选项,同时进行多个编译操作.很多 的gcc选项包括一个以上的字符.因此你必须为每个选项指定各 自 ...