Codeforces Round #287 (Div. 2) A B C


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;
	}
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章