BestCoder Round #84
来源:互联网 发布:电气原理图软件 编辑:程序博客网 时间:2024/04/28 21:38
HDU【5747】——Aaronson
Problem Description
Recently, Peter saw the equation
Input
There are multiple test cases. The first line of input contains an integer T (1≤T≤10
The first contains two integers n and m (0≤n,m≤
Output
For each test case, output the minimum value of
Sample Input
10
1 2
3 2
5 2
10 2
10 3
10 4
13 5
20 4
11 11
12 3
Sample Output
1
2
2
3
2
2
3
2
3
2
水题:将n分解成二级制,如果m小于n的位数,将剩余的加在最高位就行
#include <iostream>#include <cstdio>using namespace std;typedef long long LL;int n,m;int Get(LL s){ int ans = 0; int num = 0; while(s&&num<m) { if(s%2) ans++; num++; s>>=1; } return ans+s;}int main(){ int T; scanf("%d",&T); while(T--) { scanf("%d %d",&n,&m); int ans = Get(n); printf("%d\n",ans); } return 0;}
HDU【5748】——Bellovin
Problem Description
Peter has a sequence
Peter would like to find another sequence
The sequence
Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:
The first contains an integer n (1≤n≤100000) – the length of the sequence. The second line contains n integers
Output
For each test case, output n integers
Sample Input
3
1
10
5
5 4 3 2 1
3
1 3 5
Sample Output
1
1 1 1 1 1
1 2 3
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int N=110000;int n,val[N],a[N];int len,arr[N];int an[N];int lowbit(int x){ return x&(-x);}void update(int i,int x){ while(x<=len) { if(i>arr[x]) arr[x]=i; x+=lowbit(x); }}int query(int x){ int ans=0; while(x) { if(arr[x]>ans) ans=arr[x]; x-=lowbit(x); } return ans;}int main(){ int T; scanf("%d",&T); while(T--) { scanf("%d",&n); for(int i=0; i<n; i++) { scanf("%d",&val[i]); a[i]=val[i]; } sort(a,a+n); len=unique(a,a+n)-a; memset(arr,0,sizeof(arr)); int tmp; for(int i=0; i<n; i++) { val[i]=lower_bound(a,a+len,val[i])-a+1; tmp=query(val[i]-1)+1; update(tmp,val[i]); an[i] = tmp; } for(int i = 0;i<n;i++) { if(i) printf(" "); printf("%d",an[i]); } printf("\n"); } return 0;}
HDU【5749】——Colmerauer
Problem Description
Peter has an n×m matrix M. Let S(a,b) be the sum of the weight all a×b submatrices of M. The weight of matrix is the sum of the value of all the saddle points in the matrix. A saddle point of a matrix is an element which is both the only largest element in its column and the only smallest element in its row. Help Peter find out all the value of S(a,b).
Note: the definition of saddle point in this problem may be different with the definition you knew before.
Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:
The first contains two integers n and m (1≤n,m≤1000) – the dimensions of the matrix.
The next n lines each contain m non-negative integers separated by spaces describing rows of matrix M (each element of M is no greater than 106).
Output
For each test case, output an integer
Sample Input
3
2 2
1 1
1 1
3 3
1 2 3
4 5 6
7 8 9
3 3
1 2 1
2 3 1
4 5 2
Sample Output
4
600
215
题意:给你一个矩阵,计算所有子矩阵矩阵的值的,既矩阵的面积与鞍点的乘积。考虑每一个鞍点的贡献,假设我们已经知道某个鞍点的的上下左右的有效区间,那么我们可以得出
ans
我们可以用单调队列处理出每个鞍点在行和列的上下限,然后进行处理。
#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <algorithm>#include <iostream>using namespace std;const int Max = 1100;void read(int &ans){ char ch; while((ch = getchar())<'0' && ch >'9'); ans = ch-'0'; while((ch = getchar())>='0' && ch<='9') { ans = ans*10+ch-'0'; }}int n,m;int arr[Max][Max];int st[Max];int L[Max][Max],R[Max][Max],up[Max][Max],dn[Max][Max];unsigned cal(unsigned a,unsigned b,unsigned c,unsigned d){ return ((a+1)*(b+1)*(a+b+2)/2)*((c+1)*(d+1)*(c+d+2)/2);}int main(){ int T; read(T); while(T--) { read(n); read(m); for(int i = 1;i<=n;i++) { for(int j = 1;j<=m;j++) { read(arr[i][j]); L[i][j] = 1; R[i][j] = m; up[i][j] = 1; dn[i][j] = n; } } int top; for(int i = 1;i<=n;i++) { top = 0; st[++top] = 0; for(int j = 1;j<=m;j++) { while(top>1 && arr[i][st[top]] > arr[i][j]) { R[i][st[top]] = min(j-1,R[i][st[top]]); top--; } if(top>1 && arr[i][st[top]] == arr[i][j]) L[i][j] = max(L[i][j],st[top]+1) ; while(top>1 && arr[i][st[top]] == arr[i][j]) { R[i][st[top]] = min(j-1,R[i][st[top]]); top --; } L[i][j] = max(L[i][j],st[top]+1); st[++top] = j; } } for(int i = 1;i<=m;i++) { top = 0; st[++top] = 0; for(int j = 1;j<=n;j++) { while(top>1 && arr[st[top]][i]< arr[j][i]) { dn[st[top]][i] = min(j-1,dn[st[top]][i]); top--; } if(top >1 && arr[st[top]][i] == arr[j][i]) up[j][i] =max(up[j][i],st[top]+1); while(top>1 && arr[st[top]][i] == arr[j][i]) { dn[st[top]][i] = min(j-1,dn[st[top]][i]); top--; } up[j][i] = max(up[j][i],st[top]+1); st[++top] = j; } } unsigned int ans = 0; for(int i = 1;i<=n;i++) { for(int j = 1;j<=m;j++) { unsigned c1 = j - L[i][j]; unsigned c2 = R[i][j]-j; unsigned h1 = i - up[i][j]; unsigned h2 = dn[i][j] - i; unsigned s = arr[i][j]; ans +=cal(c1,c2,h1,h2)*s; } } cout<<ans<<endl; } return 0;}
HDU【5750】——Dertouzos
Problem Description
A positive proper divisor is a positive divisor of a number n, excluding n itself. For example, 1, 2, and 3 are positive proper divisors of 6, but 6 itself is not.
Peter has two positive integers n and d. He would like to know the number of integers below n whose maximum positive proper divisor is d.
Input
There are multiple test cases. The first line of input contains an integer T (1≤T≤
The first line contains two integers n and d (2≤n,d≤
Output
For each test case, output an integer denoting the answer.
Sample Input
9
10 2
10 3
10 4
10 5
10 6
10 7
10 8
10 9
100 13
Sample Output
1
2
1
0
0
0
0
0
4
比赛的时候手残,最后T了。问小于n的数中有多少个数的最大的因子是d,显然的事是d一定和素数相乘,并且小于等于min(
#include<iostream>#include<cstdio>#include<cstring>#include <cmath>#include<algorithm>using namespace std;const int Max = 1e7+100;int prime[Max];int vis[Max];int num[Max];void Get(){ prime[0] =0 ; num[0] = num[1] = 0; for(int i = 2; i<Max; i++) { if(!vis[i]) { prime[++prime[0]] = i; for(int j =i+i; j<Max; j+=i) { if(!vis[j]) vis[j] = i; } } num[i] = num[i-1]; if(!vis[i]) num[i]++; }}int n,p;int main(){ Get(); int T; scanf("%d",&T); while(T--) { scanf("%d %d",&n,&p); int s=(n-1)/p; if(s <= 1) { printf("0\n"); continue; } int ans = 0; for(int i = 1;i<=prime[0] && prime[i]<=s;i++) { ans++; if(p%prime[i] == 0) { break; } } printf("%d\n",ans); } return 0;}
- BestCoder Round #84 Dertouzos
- BestCoder Round #84 题解
- BestCoder Round #84
- BestCoder Round #84
- BestCoder Round #84
- BestCoder Round #84 Bellovin
- BestCoder Round #84题解报告
- BestCoder Round #84 1002 Bellovin
- BestCoder Round #84 1004Dertouzos
- Bestcoder round#84 解题报告
- BestCoder Round #84 1001 hdu 5747 模拟
- BestCoder Round #84 1004 hdu 5750 数论
- BestCoder Round #84 <LIS 2进制 思维>
- 第一次打bc BestCoder Round #84
- hdu 5747 Aaronson (BestCoder Round #84 1001)
- 【HDOJ】【BestCoder Round #84】1001 Aaronson
- 【HDOJ】【BestCoder Round #84】1004 Dertouzos
- hdoj 5748 Bellovin (LIS) 【BestCoder Round #84 】
- javaweb
- 搜索树判断
- 三人行之C从零开始
- Objective C转Swift注意事项(二)值类型和协议
- 百度地图sdk的导入
- BestCoder Round #84
- [LEETCODE] 287. Find the Duplicate Number
- javaweb
- Spring Transaction 源码
- LeetCode 9. Palindrome Number
- JAVA实践并查集
- 某券商Oracle RAC数据库服务器更换(上)
- Source Insight 常用设置和快捷键大全
- 1029. 旧键盘(20)