zoukankan      html  css  js  c++  java
  • 最后一周第二天训练赛之第二题

    试题:

    B - B
    Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

    Description

    Mathews uses a brand new 16-bit instruction processor. (Yeah i am being sarcastic!). It has one register (say R) and it supports two instructions: 

    • ADD X; Impact: R = (R + X) mod 65536
    • MUL X; Impact: R = (R * X) mod 65536
    • [For both instructions 0 <= X <= 65535]
    Mathews sees a segment of code, but doesnot know what value the register had before the code was being executed. How many possible values can the register have after the segment completed execution?
    Input Format:
    The input file consists of multiple testcases. 
    The first line of each testcase contains one integer, N. (1 <= N <= 100,000).
    The following N lines contain one instructions each. 
    Input terminates with a line containing N=0, which must not be processed. 

    Output Format:
    For each testcase print one integer in a single line, denoting the number of different values the register can take after code execution.

    Sample Input:
    1
    ADD 3
    1
    MUL 0
    5
    MUL 3
    ADD 4
    MUL 5
    ADD 3
    MUL 2
    8
    ADD 32
    MUL 5312
    ADD 7
    MUL 7
    ADD 32
    MUL 5312
    ADD 7
    MUL 7
    0
    
    Sample Output:
    65536
    1
    32768
    16
    这道题是一道传说中的水题吧,但是写的时候还是有很大的问题的。没有AC。就当做一个记录留下来吧。
    AC代码:
     1 #include <iostream>
     2 #include <cstdio>
     3 
     4 using namespace std;
     5 char ans[6];
     6 int main()
     7 {
     8     int n;
     9     while(cin>>n&&n){
    10         int aa = 65536,haha;
    11         for(int i = 0;i < n;i++){
    12         scanf("%s",ans);
    13         cin>>haha;
    14         if(ans[0]=='M'){
    15 
    16             if(haha==0){aa = 1;break;}
    17             while(haha%2==0){
    18                 haha/=2;
    19                 aa/=2;
    20             }
    21         }
    22         }
    23         if(aa>=1)
    24         cout<<aa<<endl;
    25         else cout<<1<<endl;
    26     }
    27     return 0;
    28 }
    AC代码
    我要坚持一年,一年后的成功才是我想要的。
  • 相关阅读:
    springboot 项目添加jaeger调用链监控
    使用Maven插件快捷打包发布远程Docker镜像 dockerfile-maven-plugin
    glide install失败 Update failed for golang.org/x/net: Cannot detect VCS
    Docker 修改默认存储位置
    istio 服务地图
    istio收集Metrics和日志信息
    istio分布式调用链Jaeger
    prometheus 通过企业微信接收告警
    prometheus alert rules文件格式化
    Effective C++ 笔记二 构造/析构/赋值运算
  • 原文地址:https://www.cnblogs.com/tianxia2s/p/3908358.html
Copyright © 2011-2022 走看看