码迷,mamicode.com
首页 > 其他好文 > 详细

【题解】Cards For Friends 【水题】

时间:2021-01-08 11:28:07      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:hal   ring   class   his   ==   its   hat   main   which   

A. Cards for Friends

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

For the New Year, Polycarp decided to send postcards to all his nn friends. He wants to make postcards with his own hands. For this purpose, he has a sheet of paper of size w×hw×h, which can be cut into pieces.

Polycarp can cut any sheet of paper w×hw×h that he has in only two cases:

  • If ww is even, then he can cut the sheet in half and get two sheets of size w/2×h
  • If hh is even, then he can cut the sheet in half and get two sheets of size w×h/2

If ww and hh are even at the same time, then Polycarp can cut the sheet according to any of the rules above.

After cutting a sheet of paper, the total number of sheets of paper is increased by 1

Help Polycarp to find out if he can cut his sheet of size w×hw×h at into nn or more pieces, using only the rules described above.

Input

The first line contains one integer tt (1≤t≤1e4) — the number of test cases. Then tt test cases follow.

Each test case consists of one line containing three integers w, h, n (1≤w,h≤1e4, 1≤n≤1e9) — the width and height of the sheet Polycarp has and the number of friends he needs to send a postcard to.

Output

For each test case, output on a separate line:

  • "YES", if it is possible to cut a sheet of size w×hw×h into at least nn pieces;
  • "NO" otherwise.

You can output "YES" and "NO" in any case (for example, the strings yEs, yes, Yes and YES will be recognized as positive).

 

 

题目大意:

    一张w×h的纸,如果w为偶数(或h为偶数),那么就可以把这张纸裁成两张w/2 × h(或w × h/2)的纸。已知一张纸的w和h,求最多能裁出多少张纸。

题目分析:

    显然,按照w裁剪或按照h裁剪的先后顺序对最终结果没有影响,因此,只需统计w和h中因子2的个数即可。

代码实现:

#include <bits/stdc++.h>

int t;

int num;

int w,h,n;

int main(){

     scanf("%d",&t);

     while(t--){

          scanf("%d%d%d",&w,&h,&n);

          num= 1;

          for(int i = 2;w % i == 0 ;i *= 2){

               num *= 2;

          }

          for(int i = 2;h % i == 0 ;i *= 2){

               num *= 2;

          }

          if(num<n)printf("NO\n");

          else printf("YES\n");

     }

     return 0;

}

 

【题解】Cards For Friends 【水题】

标签:hal   ring   class   his   ==   its   hat   main   which   

原文地址:https://www.cnblogs.com/tzw2698/p/14244070.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!