第一次打bc BestCoder Round #84
来源:互联网 发布:朋友印象是什么软件 编辑:程序博客网 时间:2024/04/30 12:15
今晚第一次打bc,之前bc给我的影响是很难。。。不像cf前两道题是水题来的(但自己每次都拿不下,基础太差~~)。感觉bc也不是想像的那么难(前两题),但是因为自己基础差所以思考打码的时间比较长,bc也是测试小部分数据而已,所以当第一题显示ac的时候我以为过了,但谁知最后还是没能ac。不够细心.........
发现bc基本上都是数论题,,,靠智商捉急~~~
第一题:
问题描述
给出一个不定方程x0+2x1+4x2+...+2mxm=n, 找出一组解(x0,x1,x2,...,xm), 使得i=0∑mxi最小, 并且每个xi (0≤i≤m)都是非负的.
输入描述
输入包含多组数据, 第一行包含一个整数T (1≤T≤105)表示测试数据组数. 对于每组数据:第一行包含两个整数n和m (0≤n,m≤109).
输出描述
对于每组数据, 输出i=0∑mxi的最小值.
一看就是关于二进制的问题,但是需要考虑当m小于n二进制的位数时的情况,就是这里没考虑不清楚wa了,当p(记录n的二进制位数)大于m时,需要向最高位不断乘以2才能补充超过m位以后的值。。。。自己表达不清楚,,,,例如当n=15(1111),m=1,当p>2时,第三位需要乘以2,第四位需要乘以4(2*2)。。。。#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>using namespace std;#define N 10000int b[N];int main() {#ifndef ONLINE_JUDGE freopen("in.txt","r",stdin);#endif int t,n,m; cin>>t; while(t--){ cin>>n>>m; int k=0,p=0,a=n,s=0,r=1; m++; while(a){ if(a&1) b[k++]=1; else b[k++]=0; a>>=1; } for(int i=0;i<k;i++){ //cout<<b[i]; p++; if(p>m){ r*=2; if(b[i]) s+=r; } else{ if(b[i]) s++; } } if(m==1) cout<<n<<endl; else cout<<s<<endl; } }
问题描述
Peter有一个序列a1,a2,...,an. 定义F(a1,a2,...,an)=(f1,f2,...,fn), 其中fi是以ai结尾的最长上升子序列的长度.Peter想要找到另一个序列b1,b2,...,bn使得F(a1,a2,...,an)和F(b1,b2,...,bn)相同. 对于所有可行的正整数序列, Peter想要那个字典序最小的序列.序列a1,a2,...,an比b1,b2,...,bn字典序小, 当且仅当存在一个正整数i (1≤i≤n)满足对于所有的k (1≤k<i)都有ak=bk并且ai<bi.
输入描述
输入包含多组数据, 第一行包含一个整数T表示测试数据组数. 对于每组数据:第一行包含一个整数n (1≤n≤100000)表示序列的长度. 第二行包含n个整数a1,a2,...,an (1≤ai≤109).
输出描述
对于每组数据, 输出n个整数b1,b2,...,bn (1≤bi≤109)表示那个字典序最小的序列.
输入样例
311055 4 3 2 131 3 5
输出样例
11 1 1 1 11 2 3
其实刚开始以为很复杂,很烦,而且过的人也不是很多,。、、、谁知看题解才忽然明白,其实就是求以ai(0《i<n)结尾的最长上升子序列的个数。,,
最小的字典序就是f1,f2,f3......
再次复习一次求最长上升子序列,但是这题O(n^2)做法会超时,需要nlongn。。。。复习了一遍nlongn的做法,但是不注意细节,wa了十几遍了,唉 ~~~~基础搭不牢~~~
wa的过程真的很痛苦,看不出哪里有问题但是一直wa的过程真的很费力,很烦躁~~~~
#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>using namespace std;#define N 100010#define inf 999999long long a[N],n,b[N],c[N];int main() {#ifndef ONLINE_JUDGEfreopen("in.txt","r",stdin);#endif int t; cin>>t; while(t--) { cin>>n; for(int i=0;i<n;i++) cin>>a[i]; for(int i=0;i<=n;i++) b[i]=inf; int k=0; b[k++]=a[0];c[0]=1; for(int i=1;i<n;i++){ if(a[i]>b[k-1]) { b[k++]=a[i];c[i]=k; //注意不是c[i]=c[i-1]+1; }else{int x=lower_bound(b,b+k,a[i])-b;//cout<<"x:"<<x<<endl;b[x]=a[i];c[i]=x+1;}}/*for(int i=0;i<n;i++)cout<<b[i]<<" ";cout<<"------"<<endl;*/for(int i=0;i<n-1;i++)cout<<c[i]<<" ";cout<<c[n-1]<<endl;}}
BestCoder Round #84
hdu:5747,5748
0 0
- 第一次打bc BestCoder Round #84
- BestCoder Round #92 第一次BC
- 第一次打bestcoder #72
- BestCoder Round #84 Dertouzos
- BestCoder Round #84 题解
- BestCoder Round #84
- BestCoder Round #84
- BestCoder Round #84
- BestCoder Round #84 Bellovin
- 第一次BC
- BestCoder Round #84题解报告
- BestCoder Round #84 1002 Bellovin
- BestCoder Round #84 1004Dertouzos
- Bestcoder round#84 解题报告
- 第二次打BC
- BestCoder Round #84 1001 hdu 5747 模拟
- BestCoder Round #84 1004 hdu 5750 数论
- BestCoder Round #84 <LIS 2进制 思维>
- 有 Return 的情况下 Try Catch Finally的执行顺序(详细的代码以及解释)
- List的类类型排序
- 深入理解java反射机制
- HDU 1102 Constructing Roads [已知路径修好求最小生成树]
- Android属性动画详解(一),属性动画基本用法
- 第一次打bc BestCoder Round #84
- poj -2559
- JAVA集合体系回顾(2)
- Ubuntu 中 gconf, dconf, gsettings 和 dconf-editor 的功能与使用
- C++之char*,const char*和string的相互转换
- 和四大组件关系最紧密的Intent-----意图(一)
- c语言声明
- S5PV210的定时器原理及要点----(1)
- helloworld