Google2015校园招聘在线笔试题2
下午去打了个酱油,就做出一道最简单的题,2048游戏,实在是太菜了,马上要找工作了,复习的不到位啊! 解法: k记录要被放置的位置索引 1.k位置元素是0,将e[i]移到e[k] 2.k位置非零: (1)e[i]==e[k]相同,碰撞,e[k]×=2,k移到下一个位置(k或--k) (2
下午去打了个酱油,就做出一道最简单的题,2048游戏,实在是太菜了,马上要找工作了,复习的不到位啊!
解法:
k记录要被放置的位置索引
1.k位置元素是0,将e[i]移到e[k]
2.k位置非零:
(1)e[i]==e[k]相同,碰撞,e[k]×=2,k移到下一个位置(++k或--k)
(2)e[i]!=e[k]不同,k移到下一个位置(++k或--k),将e[i]移到e[k]
复杂度O(n^2),代码有点乱,没整理,如下:
#include <iostream> #include <string> inline void arrayMove(short (*val)[21],int n,std::string&dir){ if(dir=="up"){ for(int j=0;j<n int k="0;" for i="1;i<=n-1;++i){" if continue val j="0;j<n;++j){">=0;--i){ if(0==val[i][j]) continue; if(0==val[k][j]){ val[k][j]=val[i][j]; val[i][j]=0; }else if(val[i][j]==val[k][j]){ val[k][j]=val[i][j]=0;--j){ if(0==val[i][j]) continue; if(0==val[i][k]){ val[i][k]=val[i][j]; val[i][j]=0; }else if(val[i][j]==val[i][k]){ val[i][k]=val[i][j]>T; while(++i>N; std::cin>>dir; for(int j=0;j<n for k="0;k<N;++k)" std::cin>>val[j][k]; arrayMove(val,N,dir); std::cout<br> <br> </n></n></string></iostream>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use Laravel to develop an online restaurant reservation system In recent years, with the rapid development of the Internet and mobile Internet, online reservations have become an indispensable part of modern people's lives. The catering industry is no exception. More and more restaurants are beginning to provide online reservation services to improve user experience and expand market share. This article will introduce how to use the Laravel framework to develop a simple but fully functional online restaurant reservation system, and provide specific code examples to facilitate readers to learn and practice. Environment setup First, we need

With the popularity of e-commerce, more and more businesses are adopting online invoice management systems to manage sales and invoices. When developing an online invoice management system, it is important to choose the right tools and technology. This article will introduce how to use PHP language to develop an online invoice management system and provide some useful development guidelines. Determine system requirements Before starting development, the specific requirements for an online invoice management system need to be determined. This may include the following aspects: Invoice management: saving, querying and editing invoice information; Customer information management: saving, querying and editing customers

How to use JavaWebsocket to implement online audio and video calls? In today's digital age, real-time communication is becoming more and more common. Whether it is remote collaboration at work or remote communication with relatives and friends at home, real-time audio and video calls have become an indispensable part of people. This article will introduce how to use JavaWebsocket to implement online audio and video calls, and provide specific code examples. 1. Understand WebsocketWebsocket is a new technology in HTML5

How to use PHP to implement a simple online music player. With the advent of the digital age, more and more people are beginning to enjoy music through the Internet, and online music players have become an important tool. In this article, we will implement a simple online music player through the PHP programming language and provide specific code examples. Preparation work: Before starting, we need to prepare the following aspects: a machine running a web server (such as Apache). PHP running environment. Music files, music files can be

Use JavaScript to build an online electronic signature tool. With the advent of the digital age, electronic signatures have become a fast, convenient, and secure way of business communication. When developing online electronic signature tools, JavaScript is undoubtedly a powerful language choice. This article will introduce how to use JavaScript to build a simple yet powerful online electronic signature tool, with code examples. Before we begin, we need to understand a few concepts. There are usually two types of electronic signatures: image-based signatures and vector-based signatures.

How to use PHP to implement a simple online order management system 1. Introduction Online order management system is a common e-commerce application. It can help merchants effectively manage the order process, speed up order processing, and improve customer satisfaction. This article will introduce how to use PHP to implement a simple online order management system, including the creation, modification, query and deletion of orders. This article assumes that readers already have some basic knowledge of PHP. 2. System Requirements The online order management system needs to meet the following basic requirements: Login function

How to use Laravel to develop an online customer service system Introduction: Online customer service systems play an important role in modern enterprises. It helps businesses communicate with customers in real time, answer questions, provide support, and enhance user experience. This article will introduce how to use the Laravel framework to develop a simple and practical online customer service system. 1. Design the database The online customer service system needs to store users and conversation records, so it is first necessary to design a suitable database model. In Laravel we can use the migration tool

Java programming implements random selection of test questions in the online examination system, which requires specific code examples. In modern education, using the Internet to conduct online examinations has become one of the common examination methods. In order to ensure the fairness and validity of the exam, the exam system needs to be able to randomly select test questions. This article will introduce how to use Java programming to implement random extraction of test questions in the online examination system, and provide specific code examples. First, we need to prepare test question data. Suppose we already have a test question bank. The test question bank contains multiple test questions. Each test question has
