假设您有ksize 的数组N,每个数组都包含从1to 的唯一值N。
你将如何找到平均相距最远的两个数字?
例如,给定数组:
[1,4,2,3]
[4,2,3,1]
[2,3,4,1]
Run Code Online (Sandbox Code Playgroud)
那么答案将是 item 1and 2,因为它们在前两个数组中的距离为 2,而在最后一个数组中的距离为 3。
我知道一个 O(kN^2) 解决方案(通过测量每个k数组的每对数字之间的距离),但是有更好的解决方案吗?
我想在 C++ 中实现这样的算法,但对解决方案的任何描述都会有所帮助。
我正在使用Android SearchView在我的操作栏中有一个搜索按钮.我在YouTube上关注了谷歌开发者的这个教程,并根据自己的需要添加了一些调整.但是,每当我退出单击按钮时出现的搜索字段时,搜索按钮就会消失!
这是我的onCreateOptionsMenu和onOptionsItemSelected函数
onCreateOptionsMenu:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
Run Code Online (Sandbox Code Playgroud)
onOptionsItemSelected:
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
switch (id) {
case R.id.action_settings:
// …Run Code Online (Sandbox Code Playgroud)