zoukankan      html  css  js  c++  java
  • 题解 AT3718 【[ABC081B] Shift only】

    题目传送门


    分析

    直接暴力。
    我们可以根据题意进行模拟,使用二重循环即可。


    代码讲解

    1. 定义变量(n)和计数数组(cnt),再定义数组(a)并输入。
    	int a[1000000];
    	int n,cnt=0;;
    	cin>>n;
    	int n,cnt=0;;
    	cin>>n;
    	for(int i=1;i<=n;i++)
    		cin>>a[i];
    
    1. 使用一个死循环,当无法继续(div2)时,结束循环。
    		bool pd=true;//①
    		for(int j=1;j<=n;j++) 
    		{
    			if(a[j]%2!=0)
    			{
    				pd=false;
    				break;
    			} 
    		}
    		if(pd==false)break;//②
    		if(pd)
    		{
    			cnt++;
    			for(int j=1;j<=n;j++)
    				a[j]/=2;
    		} 
    

    ①判断能否被(2)整除使用的布尔型变量。
    ②循环的结束条件。

    1. 输出最终结果。
    	cout<<cnt; 
    

    CODE

    #include <bits/stdc++.h>
    using namespace std;
    int a[1000000];
    int main()
    {
    	int n,cnt=0;;
    	cin>>n;
    	for(int i=1;i<=n;i++)
    		cin>>a[i];
    	for(int i=1;;i++)
    	{
    		bool pd=true;
    		for(int j=1;j<=n;j++) 
    		{
    			if(a[j]%2!=0)
    			{
    				pd=false;
    				break;
    			} 
    		}
    		if(pd==false)break;
    		if(pd)
    		{
    			cnt++;
    			for(int j=1;j<=n;j++)
    				a[j]/=2;
    		} 
    	} 
    	cout<<cnt; 
    	return 0;
    }
    
  • 相关阅读:
    6.4 总结(关于正确率)
    POI2013 Bytecomputer
    BZOJ1485 有趣的数列
    PAM
    BZOJ1787 meet
    BZOJ3895 rock
    URAL 1996 Cipher Message 3
    BZOJ1468 Tree
    Javascript初识之数据类型
    Javascript初识之流程控制、函数和内置对象
  • 原文地址:https://www.cnblogs.com/tearing/p/12376401.html
Copyright © 2011-2022 走看看