Codeforces Round #287 (Div. 2) A B C
来源:互联网 发布:linux route 修改路由 编辑:程序博客网 时间:2024/06/06 13:15
A
题意:Amr有n种乐器,每种乐器需要ai天学完,Amr一共有k天去学,最多能学多少种
水题,排序一下就好了....然后我没看清题意就交了一发..呵呵→_→
struct node {int id , a;bool operator < ( const node &ot ) {return a < ot.a;}}a[111];int main () {int n, k;while( cin>>n>>k ) {for( int i =0 ; i< n; ++i )scanf("%d", &a[i].a ), a[i].id = i + 1;sort( a , a + n );int ans = 0, s = 0, ed = -1;for( int i = 0; i < n; ++i ) {s += a[i].a;if( s > k ) break;++ans;ed = i;}cout<<ans<<endl;for( int i = 0; i <= ed; ++i ) printf("%d%c", a[i].id, i == ed ? '\n' : ' ' );}}
B
题意:给你圆心和半径,可以绕圆上的任意一个点旋转任意角度,问圆心到达指定点的最小操作数是多少
水题,两个点的距离除以半径的两倍后向上取整就好了
int main () {LL r, x, y, xx, yy;while( cin>>r>>x>>y>>xx>>yy ) {LL d = ( 2 * r );LL dis = ( x - xx ) * ( x - xx ) + ( y - yy ) * ( y - yy ) ;double dist = sqrt( dis + 0.0 );cout<< ceil (dist / d )<<endl;}}
C
题意:给一个完全二叉树的高度h,从根节点出发,目的地是第n个叶子节点,走的方法是“LRLRLRLRLRLRLRLRLR…………”, 问走到目的地之前经过了几个节点
观察一下就可以知道,在左儿子往右左走的时候要加上右边的节点,在右儿子往右走的时候要加上左边的所有节点,不要忘了把当前节点加上去,注意根节点当作是右儿子
cur=0表示左儿子
LL ans;LL Pow[334];void gao ( int cur, LL n, LL l, LL r, int h ) {LL m = ( l + r ) / 2;if( l == r ) return ;++ans;if( n > m ) {if( cur == 1 ) ans += Pow[h] -1;//cout<<ans<<endl;gao( 1, n, m + 1, r, h-1 );}else {if( cur == 0 ) ans += Pow[h] -1;//cout<<ans<<endl;gao( 0, n, l, m , h-1);}}int main () {int h;LL n;Pow[0] = 1;for( int i = 1; i <= 55; ++i )Pow[i] = Pow[i-1] * 2;while( cin>>h>>n ) {LL l = 1, r = 1LL << h;ans = 0;gao( 1, n, l, r , h);cout<<ans<<endl;}}
0 0
- Codeforces Round #287 (Div. 2) A、B、C、D、E
- Codeforces Round #287 (Div. 2) A B C
- Codeforces Round #287 (Div. 2)A,B,C,D,E
- [Codeforces] Round #287 (Div. 2) A、B
- Codeforces Beta Round #95 (Div. 2) A B C E
- 【CodeForce】Codeforces Round #140 (Div. 2) A B C
- 【CodeForce】Codeforces Round #142 (Div. 2) A B C
- Codeforces Round #160 (Div. 2)——A,B,C
- Codeforces Round #177 (Div. 2)——A,B,C
- Codeforces Round #179 (Div. 2)A、B、C、D
- Codeforces Round #184 (Div. 2)——A,B,C
- Codeforces Round #185 (Div. 2)——A,B,C
- Codeforces Round #186 (Div. 2)——A,B,C
- Codeforces Round #186 (Div. 2)A、B、C、D、E
- Codeforces Round #190 (Div. 2) A B C
- Codeforces Round #196 (Div. 2) A,B,C
- Codeforces Round #202 (Div. 2) (A、B、C、D)
- Codeforces Round #211 (Div. 2)(A,B,C,D)
- Nginx、Lighttpd与Apache的区别
- uva1388(数学)
- dp小结
- coco2dx 中常用的宏定义
- android SparseArray替代HashMap的分析
- Codeforces Round #287 (Div. 2) A B C
- git设置ssh key
- C++11 中的线程、锁和条件变量
- 解剖Nginx·模块开发篇(1)跑起你的 Hello World 模块!
- 八、Redis 基础命令---管理--持久化--RDB
- 交换两个变量的值
- C++11 中值得关注的几大变化(详解)
- HDU5159 Card
- 那些年我们一起追过的缓存写法(一)