wenbao与思维

 

思维真的是非常重要。。。。。

 

http://acm.hdu.edu.cn/diy/contest_showproblem.php?pid=1007&cid=30942

 

Problem Description

ACM小学妹在今天的暑假训练结束后,想看球赛放松一下。当他打开电脑时查询到联盟今天直播N场球赛,每场球赛的起止时间(S1,E1),(S2,E2),...,(SN,EN)。现在小学妹想今天看完所有的球赛直播,不至于留到明天看重播了,毕竟明天依旧是要训练的。当小学妹看完这场球赛要切换到其他球赛时是不需要时间的。现在小学妹用自己训练用的电脑来看球赛,但是可能不够。毕竟小学妹自己的电脑最多只能同时播放1场直播,现在小学妹需要借一些电脑来同时播放球赛。本来小学妹自己是可以求出最少需要借多少台电脑来同时观看的,但是今天训练太累了,你可以帮助他吗?

Input

包含多组输入,第一行输入一个整数N(1≤N≤100000),表示任务的数目。以下N行每行两个整数Si,Ei,(0≤Si<Ei≤1000000000),表示任务的起至时间。

Output

输出小学妹最少需要借的电脑数目。

Sample Input

5
1 10
2 7
6 9
3 4
7 10

Sample Output

2

 

 

 

给个代码自己体会

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <algorithm>
 4 using namespace std;
 5 const int maxn = 1e5+10;
 6 struct Node{
 7     int x, y;
 8 }T[maxn*2];
 9 int cmp(Node a, Node b){
10     if(a.x == b.x) return a.y < b.y;
11     return a.x < b.x;
12 }
13 int main(){
14     int n;
15     while(~scanf("%d", &n)){
16         int num = 0, sum = 0, ma = -1, x, y;
17         for(int i = 0; i < n; i++){
18             scanf("%d %d", &x, &y);
19             T[num].x = x, T[num].y = 1, num++;
20             T[num].x = y, T[num].y = -1, num++;
21         }
22         sort(T, T+num, cmp);
23         for(int i = 0; i < num; i++){
24             sum += T[i].y;
25             if(sum > ma) ma = sum;
26         }
27         printf("%d\n", ma-1);
28     }
29     return 0;
30 }

 

 

 

http://acm.hdu.edu.cn/diy/contest_showproblem.php?pid=1003&cid=30942

 

二叉树和

 

 1 #include <iostream>
 2 #include <stdio.h>
 3 using namespace std;
 4 #define ll long long
 5 const ll mod = 1e9+7;
 6 ll n, m;
 7 int main(){
 8     while(~scanf("%lld %lld", &n, &m)){
 9         ll sum = 1, num = 1, x;
10         while(n--){
11             x = 1LL << n;
12             if(x >= m) num ++;
13             else num += x*2, m -= x;
14             sum = (sum + num%mod) % mod;
15             //cout<<n<<" "<<x<<" "<<num<<endl;
16         }
17         printf("%lld\n", sum);
18     }
19     return 0;
20 }

 

 

 

 

 

 http://acm.hdu.edu.cn/diy/contest_showproblem.php?cid=30942&pid=1008

 

Problem Description

halfyarn找你写个简单的题?好哒!给你n个整数,现在要求你选择两个位置的数,例如选择第pos_a个数a,和第pos_b个数b,给定ans=min(a,b)*abs(pos_a-pos_b),输出ans的最大值。

Input

第一行输入一个n代表有n个数,接下来的一行输入n个整数;
2<=n<=1e6;
1<=a,b<=1e6;
注意多组输入;

Output

ans的最大值;

Sample Input

4
1 2 2 2

Sample Output

4

 

 1 #include <iostream>
 2 using namespace std;
 3 #define ll long long
 4 const int maxn = 1e6+10;
 5 ll a[maxn];
 6 int main(){
 7     int n;
 8     while(~scanf("%d", &n)){
 9         ll sum, ma = -1;
10         for(int i = 0; i < n; i++) scanf("%lld", a+i);
11         int l = 0, r = n-1;
12         while(l < r){
13             if(a[l] < a[r]) sum = (r-l)*a[l], l++;
14             else sum = (r-l)*a[r], r--;
15             if(sum > ma) ma = sum;
16         }
17         printf("%lld\n", ma);
18     }
19     return 0;
20 }

 

http://hihocoder.com/problemset/problem/1469

 福字,传说中的单调栈

 

 

 1 #include <iostream>
 2 using namespace std;
 3 const int maxn = 1009;
 4 int a[maxn][maxn], b[maxn][maxn], s[maxn];
 5 int main(){
 6     int n, m = -1, x, xx;
 7     scanf("%d", &n);
 8     for(int i = 1; i <= n; ++i){
 9         for(int j = 1; j <= n; ++j){
10             scanf("%d", &a[i][j]);
11             if(a[i][j] == a[i-1][j]+1 && i != 1){
12                 b[i][j] = b[i-1][j] + 1;
13             }else b[i][j] = 1;
14         }
15     }
16     for(int i = 1; i <= n; ++i){
17         for(int j = 1; j <= n; ++j){
18             if(a[i][j] == a[i][j-1]+1 && j != 1){
19                 x++, xx = min(xx, b[i][j]);
20             }else x = 1, xx = b[i][j];
21             int xxx = min(x, xx);
22             if(m < xxx) m = xxx;
23         }
24     }
25     printf("%d\n", m);
26 }
27 /*
28 4
29 0 0 0 0
30 0 1 2 0
31 0 2 3 0
32 0 0 0 0
33 */

 

 

 

 

 

只有不断学习才能进步!

 

posted @ 2018-04-14 13:50  wenbao  阅读(121)  评论(0编辑  收藏  举报