Codeforces Round#308

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

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <stdlib.h>
 4 #include <algorithm>
 5 #include <iostream>
 6 #include <queue>
 7 #include <stack>
 8 #include <vector>
 9 #include <map>
10 #include <set>
11 #include <string>
12 #include <math.h>
13 using namespace std;
14 #pragma warning(disable:4996)
15 typedef long long LL;
16 const int INF = 1<<30;
17 /*
18
19 */
20 int vis[101][101];
21 int main()
22 {
23     int n, a, b, c, d;
24     scanf("%d", &n);
25     for (int i = 1; i <= n; ++i)
26     {
27         scanf("%d%d%d%d", &a, &b, &c, &d);
28         for (int j = a; j <= c; ++j)
29         for (int k = b; k <= d; ++k)
30             vis[j][k]++;
31     }
32     int ans = 0;
33     for (int i = 1; i <= 100; ++i)
34     for (int j = 1; j <= 100; ++j)
35     if (vis[i][j])
36         ans += vis[i][j];
37     printf("%d\n", ans);
38     return 0;
39 }

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

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

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

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <stdlib.h>
 4 #include <algorithm>
 5 #include <iostream>
 6 #include <queue>
 7 #include <stack>
 8 #include <vector>
 9 #include <map>
10 #include <set>
11 #include <string>
12 #include <math.h>
13 using namespace std;
14 #pragma warning(disable:4996)
15 typedef __int64 LL;
16 const int INF = 1<<30;
17 /*
18
19 */
20
21 int main()
22 {
23     LL n;
24     scanf("%I64d", &n);
25     char str[11];
26     LL m = 1;
27     sprintf(str, "%I64d", n);
28     LL len = strlen(str);
29     LL ans = 0;
30     LL t = 9;
31     LL i = 0;
32     for (i = 0; i < len - 1; ++i)
33     {
34         ans = ans + t * (i + 1);
35         t *= 10;//位数为i+1的数字有多少个
36         m = m * 10;
37     }
38     ans += (i+1) * (n - m + 1);
39     printf("%I64d\n", ans);
40     return 0;
41 }

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的砝码)

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <stdlib.h>
 4 #include <algorithm>
 5 #include <iostream>
 6 #include <queue>
 7 #include <stack>
 8 #include <vector>
 9 #include <map>
10 #include <set>
11 #include <string>
12 #include <math.h>
13 using namespace std;
14 #pragma warning(disable:4996)
15 typedef long long LL;
16 const int INF = 1<<30;
17 /*
18
19 */
20 bool flag;
21 void dfs(int w, int m)
22 {
23     if (m == 1)
24     {
25         flag = true;
26         return;
27     }
28     if ((m - 1) % w == 0)
29         dfs(w, (m - 1) / w);
30     else if (m%w == 0)
31         dfs(w, m / w);
32     else if ((m + 1) % w == 0)
33         dfs(w, (m + 1) / w);
34 }
35 int main()
36 {
37     int w, m;
38     scanf("%d%d", &w, &m);
39     flag = false;
40     dfs(w, m);
41     if (flag)
42         puts("YES");
43     else
44         puts("NO");
45     return 0;
46 }

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

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <stdlib.h>
 4 #include <algorithm>
 5 #include <iostream>
 6 #include <queue>
 7 #include <stack>
 8 #include <vector>
 9 #include <map>
10 #include <set>
11 #include <string>
12 #include <math.h>
13 using namespace std;
14 #pragma warning(disable:4996)
15 typedef long long LL;
16 const int INF = 1<<30;
17 /*
18 给定n个点,问可以生成多少个三角形
19 */
20 const int N = 2000 + 10;
21 struct Point
22 {
23     int x, y;
24     bool operator<(const Point&rhs)const
25     {
26         if (x == rhs.x)
27             return y < rhs.y;
28         return x < rhs.x;
29     }
30 }a[N];
31 int main()
32 {
33     int n,i,j,k;
34     scanf("%d", &n);
35     for (i = 0; i < n; ++i)
36     {
37         scanf("%d%d", &a[i].x, &a[i].y);
38     }
39     int ans = 0;
40     for (i = 0; i < n; ++i)
41     for (j = i + 1; j < n; ++j)
42     for (k = j + 1; k < n; ++k)
43     {
44         if (a[k].x>a[j].x && a[k].y > a[j].y)
45         {
46             ans += n - k;
47             break;
48         }
49         if (a[i].x != a[j].x || a[i].x != a[k].x || a[k].x != a[i].x)
50         {
51             if(a[i].y != a[j].y || a[i].y != a[k].y || a[k].y != a[i].y)
52                 ans++;
53         }
54     }
55     printf("%d\n", ans);
56     return 0;
57 }

时间: 2024-08-11 01:36:23

Codeforces Round#308的相关文章

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

题目传送门 1 /* 2 题意:问是否能用质量为w^0,w^1,...,w^100的砝码各1个称出重量m,砝码放左边或在右边 3 暴力/进制转换:假设可以称出,用w进制表示,每一位是0,1,w-1.w-1表示砝码与物品放在一起,模拟判断每位是否ok 4 详细解释:http://blog.csdn.net/u011265346/article/details/46556361 5 总结:比赛时压根没往进制去想,连样例也不知道是怎么回事..中文不行啊:( 6 */ 7 #include <cstdi

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

题目传送门 1 /* 2 水题:读懂题目就能做 3 */ 4 #include <cstdio> 5 #include <iostream> 6 #include <algorithm> 7 #include <cstring> 8 #include <cmath> 9 #include <vector> 10 #include <string> 11 #include <queue> 12 #include

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

题目传送门 1 /* 2 水题:求总数字个数,开long long竟然莫名其妙WA了几次,也没改啥又对了:) 3 */ 4 #include <cstdio> 5 #include <iostream> 6 #include <algorithm> 7 #include <cstring> 8 #include <cmath> 9 #include <vector> 10 #include <string> 11 #inc

Codeforces Round #308 (Div. 2)

A. Vanya and Table Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right. In this table, Vanya chose n rect

2017-4-23-Train:Codeforces Round #308 (Div. 2)

A. Vanya and Table(思考) Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right. In this table, Vanya chose n 

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Educational Codeforces Round 21 G. Anthem of Berland(dp+kmp)

题目链接:Educational Codeforces Round 21 G. Anthem of Berland 题意: 给你两个字符串,第一个字符串包含问号,问号可以变成任意字符串. 问你第一个字符串最多包含多少个第二个字符串. 题解: 考虑dp[i][j],表示当前考虑到第一个串的第i位,已经匹配到第二个字符串的第j位. 这样的话复杂度为26*n*m*O(fail). fail可以用kmp进行预处理,将26个字母全部处理出来,这样复杂度就变成了26*n*m. 状态转移看代码(就是一个kmp

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿