C#简单鼠标键盘钩子KMHook
简介:由三个文件构成Pinvo.cs、KeyboardHook.cs、MouseHook.cs
Pinvo.cs 是KeyboardHook与MouseHook需要的一些常量消息的定义
KeyboardHook 是实现的一个WH_KEYBOARD_LL类型的全局键盘钩子(SetWindowsHookExA函数最后一个参数threadId=0)
MouseHook 是实现的一个WH_MOUSE_LL类型的全局鼠标按键钩子(SetWindowsHookExA函数最后一个参数threadId=0)
Pinvo
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace KMHook
{
public class HookType
{
public const int WH_CALLWNDPROC = ;
public const int WH_KEYBOARD_LL = ;
public const int WH_MOUSE_LL = ;
} public class Messages
{
public const int WM_MOUSEHOVER = 0x02A1;
public const int WM_MOUSELEAVE = 0x02A3;
public const int WM_DEVICECHANGE = 0x0219;
public const int WM_DDE_FIRST = 0x03E0;
public const int WM_BB_ENABLE = 0x00000001;
public const int WM_BB_BLURREGION = 0x00000002;
public const int WM_BB_TRANSITIONONMAXIMIZED = 0x00000004;
public const int WM_CLOAKED_APP = 0x00000001;
public const int WM_CLOAKED_SHELL = 0x00000002;
public const int WM_CLOAKED_INHERITED = 0x00000004;
public const int WM_TNP_RECTDESTINATION = 0x00000001;
public const int WM_TNP_RECTSOURCE = 0x00000002;
public const int WM_TNP_OPACITY = 0x00000004;
public const int WM_TNP_VISIBLE = 0x00000008;
public const int WM_TNP_SOURCECLIENTAREAONLY = 0x00000010;
public const int WM_SIT_DISPLAYFRAME = 0x00000001;
public const int WM_HELP = 0x0011;
public const int WM_IME_REPORT = 0x0280;
public const int WM_CONVERTREQUESTEX = 0x0109;
public const int WM_WNT_CONVERTREQUESTEX = 0x0109;
public const int WM_CONVERTREQUEST = 0x010A;
public const int WM_CONVERTRESULT = 0x010B;
public const int WM_INTERIM = 0x010C;
public const int WM_IMEKEYDOWN = 0x290;
public const int WM_IMEKEYUP = 0x291;
public const int WM_RASDIALEVENT = 0xCCCD;
public const int WM_CONTEXTMENU = 0x007B;
public const int WM_UNICHAR = 0x0109;
public const int WM_PRINTCLIENT = 0x0318;
public const int WM_NOTIFY = 0x004E;
public const int WM_HANDLED_MASK = 0x1;
public const int WM_TABLET_DEFBASE = 0x02C0;
public const int WM_TABLET_MAXOFFSET = 0x20;
public const int WM_NULL = 0x0000;
public const int WM_CREATE = 0x0001;
public const int WM_DESTROY = 0x0002;
public const int WM_MOVE = 0x0003;
public const int WM_SIZE = 0x0005;
public const int WM_ACTIVATE = 0x0006;
public const int WM_SETFOCUS = 0x0007;
public const int WM_KILLFOCUS = 0x0008;
public const int WM_ENABLE = 0x000A;
public const int WM_SETREDRAW = 0x000B;
public const int WM_SETTEXT = 0x000C;
public const int WM_GETTEXT = 0x000D;
public const int WM_GETTEXTLENGTH = 0x000E;
public const int WM_PAINT = 0x000F;
public const int WM_CLOSE = 0x0010;
public const int WM_QUERYENDSESSION = 0x0011;
public const int WM_QUERYOPEN = 0x0013;
public const int WM_ENDSESSION = 0x0016;
public const int WM_QUIT = 0x0012;
public const int WM_ERASEBKGND = 0x0014;
public const int WM_SYSCOLORCHANGE = 0x0015;
public const int WM_SHOWWINDOW = 0x0018;
public const int WM_WININICHANGE = 0x001A;
public const int WM_DEVMODECHANGE = 0x001B;
public const int WM_ACTIVATEAPP = 0x001C;
public const int WM_FONTCHANGE = 0x001D;
public const int WM_TIMECHANGE = 0x001E;
public const int WM_CANCELMODE = 0x001F;
public const int WM_SETCURSOR = 0x0020;
public const int WM_MOUSEACTIVATE = 0x0021;
public const int WM_CHILDACTIVATE = 0x0022;
public const int WM_QUEUESYNC = 0x0023;
public const int WM_GETMINMAXINFO = 0x0024;
public const int WM_PAINTICON = 0x0026;
public const int WM_ICONERASEBKGND = 0x0027;
public const int WM_NEXTDLGCTL = 0x0028;
public const int WM_SPOOLERSTATUS = 0x002A;
public const int WM_DRAWITEM = 0x002B;
public const int WM_MEASUREITEM = 0x002C;
public const int WM_DELETEITEM = 0x002D;
public const int WM_VKEYTOITEM = 0x002E;
public const int WM_CHARTOITEM = 0x002F;
public const int WM_SETFONT = 0x0030;
public const int WM_GETFONT = 0x0031;
public const int WM_SETHOTKEY = 0x0032;
public const int WM_GETHOTKEY = 0x0033;
public const int WM_QUERYDRAGICON = 0x0037;
public const int WM_COMPAREITEM = 0x0039;
public const int WM_GETOBJECT = 0x003D;
public const int WM_COMPACTING = 0x0041;
public const int WM_COMMNOTIFY = 0x0044;
public const int WM_WINDOWPOSCHANGING = 0x0046;
public const int WM_WINDOWPOSCHANGED = 0x0047;
public const int WM_POWER = 0x0048;
public const int WM_COPYDATA = 0x004A;
public const int WM_CANCELJOURNAL = 0x004B;
public const int WM_INPUTLANGCHANGEREQUEST = 0x0050;
public const int WM_INPUTLANGCHANGE = 0x0051;
public const int WM_TCARD = 0x0052;
public const int WM_USERCHANGED = 0x0054;
public const int WM_NOTIFYFORMAT = 0x0055;
public const int WM_STYLECHANGING = 0x007C;
public const int WM_STYLECHANGED = 0x007D;
public const int WM_DISPLAYCHANGE = 0x007E;
public const int WM_GETICON = 0x007F;
public const int WM_SETICON = 0x0080;
public const int WM_NCCREATE = 0x0081;
public const int WM_NCDESTROY = 0x0082;
public const int WM_NCCALCSIZE = 0x0083;
public const int WM_NCHITTEST = 0x0084;
public const int WM_NCPAINT = 0x0085;
public const int WM_NCACTIVATE = 0x0086;
public const int WM_GETDLGCODE = 0x0087;
public const int WM_SYNCPAINT = 0x0088;
public const int WM_NCMOUSEMOVE = 0x00A0;
public const int WM_NCLBUTTONDOWN = 0x00A1;
public const int WM_NCLBUTTONUP = 0x00A2;
public const int WM_NCLBUTTONDBLCLK = 0x00A3;
public const int WM_NCRBUTTONDOWN = 0x00A4;
public const int WM_NCRBUTTONUP = 0x00A5;
public const int WM_NCRBUTTONDBLCLK = 0x00A6;
public const int WM_NCMBUTTONDOWN = 0x00A7;
public const int WM_NCMBUTTONUP = 0x00A8;
public const int WM_NCMBUTTONDBLCLK = 0x00A9;
public const int WM_NCXBUTTONDOWN = 0x00AB;
public const int WM_NCXBUTTONUP = 0x00AC;
public const int WM_NCXBUTTONDBLCLK = 0x00AD;
public const int WM_INPUT_DEVICE_CHANGE = 0x00FE;
public const int WM_INPUT = 0x00FF;
public const int WM_KEYFIRST = 0x0100;
public const int WM_CHAR = 0x0102;
public const int WM_DEADCHAR = 0x0103;
public const int WM_SYSCHAR = 0x0106;
public const int WM_SYSDEADCHAR = 0x0107;
public const int WM_KEYLAST = 0x0109;
public const int WM_IME_STARTCOMPOSITION = 0x010D;
public const int WM_IME_ENDCOMPOSITION = 0x010E;
public const int WM_IME_COMPOSITION = 0x010F;
public const int WM_IME_KEYLAST = 0x010F;
public const int WM_INITDIALOG = 0x0110;
public const int WM_COMMAND = 0x0111;
public const int WM_SYSCOMMAND = 0x0112;
public const int WM_TIMER = 0x0113;
public const int WM_HSCROLL = 0x0114;
public const int WM_VSCROLL = 0x0115;
public const int WM_INITMENU = 0x0116;
public const int WM_INITMENUPOPUP = 0x0117;
public const int WM_GESTURE = 0x0119;
public const int WM_GESTURENOTIFY = 0x011A;
public const int WM_MENUSELECT = 0x011F;
public const int WM_MENUCHAR = 0x0120;
public const int WM_ENTERIDLE = 0x0121;
public const int WM_MENURBUTTONUP = 0x0122;
public const int WM_MENUDRAG = 0x0123;
public const int WM_MENUGETOBJECT = 0x0124;
public const int WM_UNINITMENUPOPUP = 0x0125;
public const int WM_MENUCOMMAND = 0x0126;
public const int WM_CHANGEUISTATE = 0x0127;
public const int WM_UPDATEUISTATE = 0x0128;
public const int WM_QUERYUISTATE = 0x0129;
public const int WM_CTLCOLORMSGBOX = 0x0132;
public const int WM_CTLCOLOREDIT = 0x0133;
public const int WM_CTLCOLORLISTBOX = 0x0134;
public const int WM_CTLCOLORBTN = 0x0135;
public const int WM_CTLCOLORDLG = 0x0136;
public const int WM_CTLCOLORSCROLLBAR = 0x0137;
public const int WM_CTLCOLORSTATIC = 0x0138;
public const int WM_MOUSEFIRST = 0x0200;
//public const int WM_LBUTTONDBLCLK = 0x0203;
//public const int WM_RBUTTONDBLCLK = 0x0206;
//public const int WM_MBUTTONDBLCLK = 0x0209;
public const int WM_MOUSEWHEEL = 0x020A;
public const int WM_XBUTTONDOWN = 0x020B;
public const int WM_XBUTTONUP = 0x020C;
public const int WM_XBUTTONDBLCLK = 0x020D;
public const int WM_MOUSEHWHEEL = 0x020E;
public const int WM_MOUSELAST = 0x020E;
public const int WM_PARENTNOTIFY = 0x0210;
public const int WM_ENTERMENULOOP = 0x0211;
public const int WM_EXITMENULOOP = 0x0212;
public const int WM_NEXTMENU = 0x0213;
public const int WM_SIZING = 0x0214;
public const int WM_CAPTURECHANGED = 0x0215;
public const int WM_MOVING = 0x0216;
public const int WM_POWERBROADCAST = 0x0218;
public const int WM_MDICREATE = 0x0220;
public const int WM_MDIDESTROY = 0x0221;
public const int WM_MDIACTIVATE = 0x0222;
public const int WM_MDIRESTORE = 0x0223;
public const int WM_MDINEXT = 0x0224;
public const int WM_MDIMAXIMIZE = 0x0225;
public const int WM_MDITILE = 0x0226;
public const int WM_MDICASCADE = 0x0227;
public const int WM_MDIICONARRANGE = 0x0228;
public const int WM_MDIGETACTIVE = 0x0229;
public const int WM_MDISETMENU = 0x0230;
public const int WM_ENTERSIZEMOVE = 0x0231;
public const int WM_EXITSIZEMOVE = 0x0232;
public const int WM_DROPFILES = 0x0233;
public const int WM_MDIREFRESHMENU = 0x0234;
public const int WM_POINTERDEVICECHANGE = 0x238;
public const int WM_POINTERDEVICEINRANGE = 0x239;
public const int WM_POINTERDEVICEOUTOFRANGE = 0x23A;
public const int WM_TOUCH = 0x0240;
public const int WM_NCPOINTERUPDATE = 0x0241;
public const int WM_NCPOINTERDOWN = 0x0242;
public const int WM_NCPOINTERUP = 0x0243;
public const int WM_POINTERUPDATE = 0x0245;
public const int WM_POINTERDOWN = 0x0246;
public const int WM_POINTERUP = 0x0247;
public const int WM_POINTERENTER = 0x0249;
public const int WM_POINTERLEAVE = 0x024A;
public const int WM_POINTERACTIVATE = 0x024B;
public const int WM_POINTERCAPTURECHANGED = 0x024C;
public const int WM_TOUCHHITTESTING = 0x024D;
public const int WM_POINTERWHEEL = 0x024E;
public const int WM_POINTERHWHEEL = 0x024F;
public const int WM_POINTERROUTEDTO = 0x0251;
public const int WM_POINTERROUTEDAWAY = 0x0252;
public const int WM_POINTERROUTEDRELEASED = 0x0253;
public const int WM_IME_SETCONTEXT = 0x0281;
public const int WM_IME_NOTIFY = 0x0282;
public const int WM_IME_CONTROL = 0x0283;
public const int WM_IME_COMPOSITIONFULL = 0x0284;
public const int WM_IME_SELECT = 0x0285;
public const int WM_IME_CHAR = 0x0286;
public const int WM_IME_REQUEST = 0x0288;
public const int WM_IME_KEYDOWN = 0x0290;
public const int WM_IME_KEYUP = 0x0291;
public const int WM_NCMOUSEHOVER = 0x02A0;
public const int WM_NCMOUSELEAVE = 0x02A2;
public const int WM_WTSSESSION_CHANGE = 0x02B1;
public const int WM_TABLET_FIRST = 0x02;
public const int WM_TABLET_LAST = 0x02;
public const int WM_DPICHANGED = 0x02E0;
public const int WM_DPICHANGED_BEFOREPARENT = 0x02E2;
public const int WM_DPICHANGED_AFTERPARENT = 0x02E3;
public const int WM_GETDPISCALEDSIZE = 0x02E4;
public const int WM_CUT = 0x0300;
public const int WM_COPY = 0x0301;
public const int WM_PASTE = 0x0302;
public const int WM_CLEAR = 0x0303;
public const int WM_UNDO = 0x0304;
public const int WM_RENDERFORMAT = 0x0305;
public const int WM_RENDERALLFORMATS = 0x0306;
public const int WM_DESTROYCLIPBOARD = 0x0307;
public const int WM_DRAWCLIPBOARD = 0x0308;
public const int WM_PAINTCLIPBOARD = 0x0309;
public const int WM_VSCROLLCLIPBOARD = 0x030A;
public const int WM_SIZECLIPBOARD = 0x030B;
public const int WM_ASKCBFORMATNAME = 0x030C;
public const int WM_CHANGECBCHAIN = 0x030D;
public const int WM_HSCROLLCLIPBOARD = 0x030E;
public const int WM_QUERYNEWPALETTE = 0x030F;
public const int WM_PALETTEISCHANGING = 0x0310;
public const int WM_PALETTECHANGED = 0x0311;
public const int WM_HOTKEY = 0x0312;
public const int WM_PRINT = 0x0317;
public const int WM_APPCOMMAND = 0x0319;
public const int WM_THEMECHANGED = 0x031A;
public const int WM_CLIPBOARDUPDATE = 0x031D;
public const int WM_DWMCOMPOSITIONCHANGED = 0x031E;
public const int WM_DWMNCRENDERINGCHANGED = 0x031F;
public const int WM_DWMCOLORIZATIONCOLORCHANGED = 0x0320;
public const int WM_DWMWINDOWMAXIMIZEDCHANGE = 0x0321;
public const int WM_DWMSENDICONICTHUMBNAIL = 0x0323;
public const int WM_DWMSENDICONICLIVEPREVIEWBITMAP = 0x0326;
public const int WM_GETTITLEBARINFOEX = 0x033F;
public const int WM_HANDHELDFIRST = 0x0358;
public const int WM_HANDHELDLAST = 0x035F;
public const int WM_AFXFIRST = 0x0360;
public const int WM_AFXLAST = 0x037F;
public const int WM_PENWINFIRST = 0x0380;
public const int WM_PENWINLAST = 0x038F;
public const int WM_APP = 0x8000;
public const int WM_USER = 0x0400;
public const int WM_CT_REPEAT_FIRST_FIELD = 0x10;
public const int WM_CT_BOTTOM_FIELD_FIRST = 0x20;
public const int WM_CT_TOP_FIELD_FIRST = 0x40;
public const int WM_CT_INTERLACED = 0x80;
public const int WM_MAX_VIDEO_STREAMS = 0x3;
public const int WM_MAX_STREAMS = 0x3; public const int WM_KEYDOWN = 0x100;
public const int WM_KEYUP = 0x101;
public const int WM_SYSKEYDOWN = 0x104;
public const int WM_SYSKEYUP = 0x105; public const int WM_MOUSEMOVE = 0x200;
public const int WM_LBUTTONDOWN = 0x201;
public const int WM_RBUTTONDOWN = 0x204;
public const int WM_MBUTTONDOWN = 0x207;
public const int WM_LBUTTONUP = 0x202;
public const int WM_RBUTTONUP = 0x205;
public const int WM_MBUTTONUP = 0x208;
public const int WM_LBUTTONDBLCLK = 0x203;
public const int WM_RBUTTONDBLCLK = 0x206;
public const int WM_MBUTTONDBLCLK = 0x209;
}
}
KeyboardHook
using System;
using System.Runtime.InteropServices; namespace KMHook
{
public class KeyboardHook : IDisposable
{
[DllImport("user32.dll")]
private static extern int SetWindowsHookExA(int idHook, KeyboardDelegateHandler lpfn, IntPtr hInstance, int threadId);
[DllImport("user32.dll")]
private static extern int CallNextHookEx(int idHook, int nCode, int wParam, KeyData lParam);
[DllImport("user32.dll")]
public static extern bool UnhookWindowsHookEx(int idHook); private int hookType = ;
private delegate int KeyboardDelegateHandler(int nCode, int wParam, KeyData lParam); public delegate bool KeyDelegate(KeyData keyData, int message);
public delegate bool KeyUpUpDelegate(KeyData keyData);
public delegate bool KeyDownDelegate(KeyData keyData);
public event KeyDelegate keyEvent;
public event KeyUpUpDelegate keyUpEvent;
public event KeyUpUpDelegate keyDownEvent; public bool IsHooked
{
get
{
if (hookType != )
{
return true;
} return false;
}
} /// <summary>
/// vkCode 表示1到254间的虚拟键盘码
/// scanCode 表示硬件扫描码
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public class KeyData
{
public int vkCode;
public int scanCode;
public int flags;
public int time;
public int dwExtraInfo;
} public void SetupHook()
{
hookType = SetWindowsHookExA(HookType.WH_KEYBOARD_LL, KMProc, IntPtr.Zero, );
if (hookType == )
{
RemoveHook();
}
} private void RemoveHook()
{
bool retKeyboard = UnhookWindowsHookEx(hookType);
if (retKeyboard)
{
hookType = ;
}
} private int KMProc(int nCode, int wParam, KeyData lParam)
{
if (!(nCode >= ))
{
return CallNextHookEx(hookType, nCode, wParam, lParam);
} bool shouldBlock = false;
if (keyEvent != null)
{
shouldBlock = keyEvent.Invoke(lParam, wParam);
} if (wParam == Messages.WM_KEYDOWN ||
wParam == Messages.WM_SYSKEYDOWN)
{
if (keyDownEvent != null)
{
shouldBlock = keyDownEvent.Invoke(lParam);
}
} if (wParam == Messages.WM_KEYUP ||
wParam == Messages.WM_SYSKEYUP)
{
if (keyUpEvent != null)
{
shouldBlock = keyUpEvent.Invoke(lParam);
}
} if (!shouldBlock)
{
return CallNextHookEx(hookType, nCode, wParam, lParam);
} return ;
} public void Dispose()
{
RemoveHook();
}
}
}
MouseHook
using System;
using System.Runtime.InteropServices; namespace KMHook
{
public class MouseHook: IDisposable
{
[DllImport("user32.dll")]
private static extern int SetWindowsHookExA(int idHook, MouseDelegateHandler lpfn, IntPtr hInstance, int threadId);
[DllImport("user32.dll")]
private static extern bool UnhookWindowsHookEx(int idHook);
[DllImport("user32.dll")]
private static extern int CallNextHookEx(int idHook, int nCode, int wParam, MouseData lParam); private delegate int MouseDelegateHandler(int nCode, int wParam, MouseData lParam);
public delegate bool MouseDelegate(MouseData pt, int message);
public event MouseDelegate mouseEvent; private int hookType = ; [StructLayout(LayoutKind.Sequential)]
public class Point
{
public int x;
public int y;
} [StructLayout(LayoutKind.Sequential)]
public class MouseData
{
public Point pt;
public int hWnd;
public int wHitTestCode;
public int dwExtraInfo;
} public bool IsHooked
{
get
{
if (hookType != )
{
return true;
} return false;
}
} public void SetupHook()
{
hookType = SetWindowsHookExA(HookType.WH_MOUSE_LL, KMProc, IntPtr.Zero, );
if (hookType == )
{
RemoveHook();
}
} private void RemoveHook()
{
bool retKeyboard = UnhookWindowsHookEx(hookType);
if (retKeyboard)
{
hookType = ;
}
} private int KMProc(int nCode, int wParam, MouseData lParam)
{
if (!(nCode >= ))
{
return CallNextHookEx(hookType, nCode, wParam, lParam);
} bool shouldBlock = false;
if (mouseEvent != null)
{
shouldBlock = mouseEvent.Invoke(lParam, wParam);
} if (!shouldBlock)
{
return CallNextHookEx(hookType, nCode, wParam, lParam);
} return ;
} public void Dispose()
{
RemoveHook();
}
}
}
代码使用情况
KeyboardHook keyboardHook = new KeyboardHook();
keyboardHook.keyEvent += (keyData, message) =>
{ if (message == Messages.WM_KEYDOWN || message == Messages.WM_SYSKEYDOWN)
{
if (keyData.vkCode == (int) Keys.A) Console.WriteLine("key a pressed.");
if (keyData.vkCode == (int) Keys.F1) Console.WriteLine("f1 pressed.");
if (keyData.vkCode == (int) Keys.Delete) Console.WriteLine("delete pressed.");
if (keyData.vkCode == (int) Keys.LControlKey) Console.WriteLine("left control pressed.");
} return true;
};
keyboardHook.SetupHook();
C#简单鼠标键盘钩子KMHook的更多相关文章
- C#鼠标键盘钩子
using System;using System.Collections.Generic; using System.Reflection; using System.Runtime.Interop ...
- 基于tensorflow的简单鼠标键盘识别
import cv2 as cvimport tensorflow as tfimport numpy as npimport random ##以下为数据预处理,分类为cata,总共样本为cata* ...
- C#键盘钩子 鼠标钩子
最新对C#模拟键盘按键,鼠标操作产生了兴趣.特从网上收集了一些常用的API用来调用键盘,鼠标操作. class Win32API { #region DLL导入 /// <summary> ...
- 用鼠标键盘来控制你的Android手机——同屏显示简单教程
今天在微博上看到有人用电脑鼠标操作iPhone手机玩打飞机游戏,非常炫,虽然自己用的不是iPhone,但相信Android手机肯定也能实现这样的功能,于是网上各种搜索方法,终于看到了一篇试用成功的帖子 ...
- Python——pyHook监听鼠标键盘事件
pyHook包为Windows中的全局鼠标和键盘事件提供回调. 底层C库报告的信息包括事件的时间,事件发生的窗口名称,事件的值,任何键盘修饰符等. 而正常工作需要pythoncom等操作系统的API的 ...
- C#实现键盘钩子
前言: 因为项目中需要使用到快捷键,所以上网找资料了解关于快捷键的实现技术,于是有了键盘钩子的使用学习.在网上了解到,键盘钩子其实只是很多种钩子中的其中一种.所谓钩子:请看下面关于钩子的描述(来自百度 ...
- c# 使用hook来监控鼠标键盘事件的示例代码
如果这个程序在10几年前,QQ刚刚兴起的时候,有了这个代码,就可实现盗号了. 当然使用钩子我们更多的是实现"全局快捷键"的需求. 比如 程序最小化隐藏后要"某快捷键&qu ...
- C#全局鼠标键盘Hook
原文出自:http://www.cnblogs.com/iEgrhn/archive/2008/02/17/1071392.html using System; using System.Collec ...
- synergy一个鼠标键盘控制多台电脑
有些时候我们同时操作多台电脑,但是我们只用一个鼠标和一个键盘,如果通过转换器啊或者是多个鼠标键盘就非常不方便了 下面我介绍一下通过安装synergy这个软件来给开发人员提供方便 这个软件安装比较简单, ...
随机推荐
- 查找第K大的值
这种题一般是给定N个数,然后N个数之间通过某种计算得到了新的数列,求这新的数列的第K大的值 POJ3579 题意: 用$N$个数的序列$x[i]$,生成一个新序列$b$. 新的序列定义为:对于任意的$ ...
- CF926B Add Points
一道尚未评定的水题 更好的阅读体验 思路 来分析分析样例: 3 -5 10 5 我们把它升序排列,会得到这个东西↑ 不仔细地观察后可以发现:加一个(0,0)的点显然是最优的 再用脚趾头想想为什么,我们 ...
- Java遍历字符串数组的几种方法
1. for循环 for(int i = 0; i < fields[].length; i++){ } 2 for each循环 for(String x:fields){ } 3. JDK8 ...
- 基于Docker的Consul集群实现服务发现
服务发现 其实简单说,服务发现就是解耦服务与IP地址之间的硬绑定关系,以典型的集群为例,对于集群来说,是有多个节点的,这些节点对应多个IP(或者同一个IP的不同端口号),集群中不同节点责任是不一样的. ...
- Codeforces Round #599 (Div. 2) D. 0-1 MST(bfs+set)
Codeforces Round #599 (Div. 2) D. 0-1 MST Description Ujan has a lot of useless stuff in his drawers ...
- python3-cookbook笔记:第三章 数字日期和时间
python3-cookbook中每个小节以问题.解决方案和讨论三个部分探讨了Python3在某类问题中的最优解决方式,或者说是探讨Python3本身的数据结构.函数.类等特性在某类问题上如何更好地使 ...
- Spring学习笔记-高级装配-03
主要内容: ●Spring profile ●条件化的bean声明 ●自动装配与歧义性 ● Spring表达式语言 本章介绍一些高级的装配技术,可实现更为高级的装配功能. 环境与profile 软件开 ...
- Spark学习之路 (二十七)图简介[转]
test test test test test test test test test 图 基本概念 图是由顶点集合(vertex)及顶点间的关系集合(边edge)组成的一种数据结构. 这里的图并非 ...
- TCP 协议快被淘汰了,UDP 协议才是新世代的未来?
TCP 协议可以说是今天互联网的基石,作为可靠的传输协议,在今天几乎所有的数据都会通过 TCP 协议传输,然而 TCP 在设计之初没有考虑到现今复杂的网络环境,当你在地铁上或者火车上被断断续续的网络折 ...
- 收录了老师发的几个 download ebook and paper 的 webpage
Library Genesis (important) http://zh.b-ok.org National Academic Press OpenStax CNX gen.lib.rus.ec l ...