D. Divide by three, multiply by two

本文介绍了一个关于整数操作的算法题目实现,通过遍历输入的整数序列,寻找可以被三整除且乘以二或能被二整除且除以二的数对,并逆向追踪这些操作,最终输出原始起点的整数。

D. Divide by three, multiply by two

//map,long long int
#include<bits/stdc++.h>
using namespace std;
vector<long long int>a;
map<long long int , int>pre;
map<long long int, long long int>prea;
map<long long int , long long int>preb;
int main()
{
    int n;
    scanf("%d", &n);
    for(int i=0;i<n;i++)
    {
        long long int x;
        scanf("%lld", &x);
        a.push_back(x);
        pre[x]=1;
    }
    sort(a.begin(), a.end());
    long long int point;
    for(int i=0;i<n;i++)
    {
       long long int x = a[i]*3;
       long long int y = 0;
       if(a[i]%2==0)
       {
           y = a[i]/2;
       }
     //  cout<<a[i]<<"@@@@@@@"<<x<<"****"<<y<<"^^^^^^"<<pre[x]<<"^^^^"<<pre[y]<<endl;
       if(pre[x])
           {
               prea[x] = a[i];
               preb[a[i]] = x;
           }
       else if(pre[y])
       {
           prea[y] = a[i];
           preb[a[i]] = y;
       }
       else
        point = a[i];
    }
    for(int i=0;i<n;i++)
    {
       // printf("**%lld %lld**\n", prea[a[i]],  preb[a[i]]);
        printf("%lld%c", point ,i==n-1?'\n':' ');
        point = prea[point];
    }
    return 0;
}
帮忙把keycodes.lua文件里的所有按键都补上, 用16进制; local M = {} -- 字母键 M.A = 65; M.B = 66; M.C = 67; M.D = 68; M.E = 69; M.F = 70; M.G = 71 M.H = 72; M.I = 73; M.J = 74; M.K = 75; M.L = 76; M.M = 77; M.N = 78 M.O = 79; M.P = 80; M.Q = 81; M.R = 82; M.S = 83; M.T = 84; M.U = 85 M.V = 86; M.W = 87; M.X = 88; M.Y = 89; M.Z = 90 -- 数字键 M.ZERO = 48; M.ONE = 49; M.TWO = 50; M.THREE = 51; M.FOUR = 52 M.FIVE = 53; M.SIX = 54; M.SEVEN = 55; M.EIGHT = 56; M.NINE = 57 -- 功能键 M.F1 = 112; M.F2 = 113; M.F3 = 114; M.F4 = 115; M.F5 = 116; M.F6 = 117 M.F7 = 118; M.F8 = 119; M.F9 = 120; M.F10 = 121; M.F11 = 122; M.F12 = 123 -- 控制键 M.BACKSPACE = 8 -- 退格键 M.TAB = 9 -- 制表符 M.ENTER = 13 -- 回车键 M.SHIFT = 16 -- Shift键 M.CTRL = 17 -- Control键 M.ALT = 18 -- Alt键 M.PAUSE = 19 -- 暂停键 M.CAPSLOCK = 20 -- 大写锁定键 M.ESCAPE = 27 -- ESC键 M.SPACE = 32 -- 空格键 M.PAGEUP = 33 -- PageUp M.PAGEDOWN = 34 -- PageDown M.END = 35 -- End键 M.HOME = 36 -- Home键 M.LEFT = 37 -- 左箭头 M.UP = 38 -- 上箭头 M.RIGHT = 39 -- 右箭头 M.DOWN = 40 -- 下箭头 M.INSERT = 45 -- Insert键 M.DELETE = 46 -- Delete键 -- 小键盘键 M.NUMPAD0 = 96; M.NUMPAD1 = 97; M.NUMPAD2 = 98; M.NUMPAD3 = 99 M.NUMPAD4 = 100; M.NUMPAD5 = 101; M.NUMPAD6 = 102; M.NUMPAD7 = 103 M.NUMPAD8 = 104; M.NUMPAD9 = 105 M.NUMPAD_MULTIPLY = 106 -- * M.NUMPAD_ADD = 107 -- + M.NUMPAD_SUBTRACT = 109 -- - M.NUMPAD_DECIMAL = 110 -- . M.NUMPAD_DIVIDE = 111 -- / M.NUMLOCK = 144 -- 数字锁定 -- 符号键 M.SEMICOLON = 186 -- ; M.EQUAL = 187 -- = M.COMMA = 188 -- , M.MINUS = 189 -- - M.PERIOD = 190 -- . M.SLASH = 191 -- / M.BACKQUOTE = 192 -- ` M.LEFTBRACKET = 219 -- [ M.BACKSLASH = 220 -- \ M.RIGHTBRACKET = 221 -- ] M.QUOTE = 222 -- ' -- 特殊功能键 M.WIN = 91 -- Windows键 M.CONTEXT_MENU = 93 -- 右键菜单键 M.PRINTSCREEN = 44 -- 打印屏幕 M.SCROLLLOCK = 145 -- 滚动锁定 -- 媒体键 M.VOLUME_MUTE = 173 -- 静音 M.VOLUME_DOWN = 174 -- 音量减 M.VOLUME_UP = 175 -- 音量加 M.MEDIA_NEXT = 176 -- 下一曲 M.MEDIA_PREV = 177 -- 上一曲 M.MEDIA_STOP = 178 -- 停止 M.MEDIA_PLAY_PAUSE = 179 -- 播放/暂停
最新发布
11-08
1. Problem Description: A complex number is a number of the form a +bi, where a and b are real numbers and i is √-1 The numbers a and b are known as the real part and imaginary part of the complex number, respectively. You can perform addition, subtraction, multiplication, and division for complex numbers using the following formula: a+bi+c+di=(a+c)+(b+d)i a+bi-(c+di)=(a-c)+(b-d)i 第2页共2页 (a+bi)*(c+di)=(ac-bd)+(bc+ad)i (a+bi)/c+di)=(ac+bd)/c²+d²)+(bc-ad)i/(c²+d²) You can also obtain the absolute value for a complex number using the following formula: latbil=√a²+b (A complex number can be interpreted as a point on a plane by identifying the (a, b) values as the coordinates of the point. The absolute value of the complex number corresponds to the distance of the point to the origin, as shown in Figure 13.12b.) Design a class named Complex for representing complex numbers and the methods add, subtract, multiply, divide, abs for performing complex-number operations, and override toString method for returning a string representation for a complex number. The toString method returns a + bi as a string. If b is 0, it simply returns a. Provide three constructors Complex(a, b), Complex(a), and Complex(). Complex() creates a Complex object for number 0 and Complex(a) creates a Complex object with 0 for b. Also provide the getRealPart() and getlmaginaryPart() methods for returning the real and imaginary part of the complex number, respectively. Your Complex class should also implement the Cloneable interface. Write a test program that prompts the user to enter two complex numbers and display the result of their addition, subtraction, multiplication, and division. Here is a sample run: <Output> Enter the first complex number: 3.5 5.5 Enter the second complex number:-3.5 1 (3.5 + 5.5i) +(-3.5 + 1.0i)= 0.0 + 6.5 (3.5 + 5.5i)-(-3.5 + 1.0i)= 7.0 + 4.5i (3.5 + 5.5i)*(-3.5 + 1.0i) =-17.75 +-15.75i (3.5 + 5.5i) /(-3.5 + 1.0i)=-0.5094 +-1.7i |3.5 + 5.5il = 6.519202405202649 <End Output>
06-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值