当前位置:  编程技术>移动开发
本页文章导读:
    ▪HDU 4597 Play Game 2013 ACM-ICPC吉林市通化全国邀请赛H题        HDU 4597 Play Game 2013 ACM-ICPC吉林通化全国邀请赛H题九野的博客,转载请注明出处:  http://blog.csdn.net/acmmmm/article/details/10833941 题意:给定T个测试数据,下面有2副牌,每副n张,每张都有一个分.........
    ▪ Instruments的运用 逻辑查错,内存泄漏分析等工具集        Instruments的使用 逻辑查错,内存泄漏分析等工具集原创文章,转载请注明 XCode 开发后期,要对代码进行改进和优化,查内存泄漏是其中一项重要工作,今天下午偷了点时间,把前段时间的.........
    ▪ Cordova CLI源码分析(6)——添加插件       Cordova CLI源码分析(六)——添加插件添加插件源码位于src/plugin.js 不再详细分析,主要用到plugman,也是Cordova 提供的用于安装和卸载插件的工具,见https://npmjs.org/package/plugman 主要内容摘录.........

[1]HDU 4597 Play Game 2013 ACM-ICPC吉林市通化全国邀请赛H题
    来源: 互联网  发布时间: 2014-02-18
HDU 4597 Play Game 2013 ACM-ICPC吉林通化全国邀请赛H题

九野的博客,转载请注明出处:  http://blog.csdn.net/acmmmm/article/details/10833941

题意:给定T个测试数据,下面有2副牌,每副n张,每张都有一个分值

问:2个人轮流取牌,每次取一张(从任意一副的牌顶或牌底取),先手可获得的最大分值

 

开始往博弈想了,这题是记忆化搜索

#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<set>
#include<math.h>
#include<string.h>
#define N 25
using namespace std;

int card1[N],card2[N],sum1[N],sum2[N];
int dp[N][N][N][N];  // dp[below1][top1][below2][top2] 表示当2个牌堆是这样时可以取得的最大值
inline int Max(int a,int b){return a>b?a:b;}

int dfs(int below1,int top1,int below2,int top2){//返回 牌堆是这样时能取得的最大值
	if(dp[below1][top1][below2][top2]!=-1)return dp[below1][top1][below2][top2];

	if(below1>top1 && below2>top2) {//牌堆取完
		dp[below1][top1][below2][top2]=0;
		return 0;
	}

	int sum=0,ans=0;//sum表示剩下牌堆的总分
	if(below1<=top1)sum+= sum1[top1]-sum1[below1-1];
	if(below2<=top2)sum+= sum2[top2]-sum2[below2-1];
	if(below1<=top1){
		ans=Max(ans,sum-dfs(below1+1,top1,below2,top2));
		ans=Max(ans,sum-dfs(below1,top1-1,below2,top2));
	}
	if(below2<=top2){
		ans=Max(ans,sum-dfs(below1,top1,below2+1,top2));
		ans=Max(ans,sum-dfs(below1,top1,below2,top2-1));
	}
	return dp[below1][top1][below2][top2]=ans;
}
int main(){
	int T,i,n;scanf("%d",&T);
	while(T--)
	{
		scanf("%d",&n);
		for(i=1;i<=n;i++)scanf("%d",&card1[i]);
		for(i=1;i<=n;i++)scanf("%d",&card2[i]);
		sum1[0]=sum2[0]=0;
		for(i=1;i<=n;i++)
			sum1[i]=sum1[i-1]+card1[i],sum2[i]=sum2[i-1]+card2[i];
		memset(dp,-1,sizeof(dp));
		printf("%d\n",dfs(1,n,1,n));
	}
	return 0;
}


 


    
[2] Instruments的运用 逻辑查错,内存泄漏分析等工具集
    来源: 互联网  发布时间: 2014-02-18
Instruments的使用 逻辑查错,内存泄漏分析等工具集

原创文章,转载请注明


XCode 开发后期,要对代码进行改进和优化,查内存泄漏是其中一项重要工作,今天下午偷了点时间,把前段时间的代码稍微整理了一下,顺带用了下这个工具,还真发现了些问题。这里记录一下,以备忘!


为了能直接地看到有问题的代码的出处,故意写了如下代码:


    Player* l_player = new Player();
    CCLog("%d", l_player->getCurrentSceneIndex());
    char* l_a = (char*)malloc(100);
    memset(l_a, 0, 100);
    CCLog("%s", l_a);

开始查错



这个过程需要点时间,然后弹出



选择IOS->Memory->Leaks 如上图
在Leaks下选择Call Tree, 在内存提示泄漏处展开调用的堆栈



在自己的逻辑代码中写进去查看




这里就是新发现的内存泄漏的地方,
加上

    //Delete l_pData >=-Rct-=<
    CC_SAFE_DELETE_ARRAY(l_pData);
这个问题解决。另入一处泄漏便是上面所加的测试代码




把这一处测试代码也删除,重新XCode->Profile, 所有问题解决




以上!



    
[3] Cordova CLI源码分析(6)——添加插件
    来源: 互联网  发布时间: 2014-02-18
Cordova CLI源码分析(六)——添加插件

添加插件源码位于src/plugin.js 不再详细分析,主要用到plugman,也是Cordova 提供的用于安装和卸载插件的工具,见https://npmjs.org/package/plugman

主要内容摘录如下:

1环境:需要git工具支持

2 命令行使用

plugman install --platform <ios|android|blackberry10|wp7|wp8> --project <directory> --plugin <name|url|path> [--plugins_dir <directory>] [--www <directory>] [--variable <name>=<value> [--variable <name>=<value> ...]]
plugman uninstall --platform <ios|android|blackberr10|wp7|wp8> --project <directory> --plugin <id> [--www <directory>] [--plugins_dir <directory>]

· Using minimum parameters, installs a plugin into a cordova project. You must specify a platform and cordova project location for that platform. You also must specify a plugin, with the different --plugin parameter forms being:

o name: The directory name where the plugin contents exist. This must be an existing directory under the --plugins_dir path (see below for more info) or a plugin in the Cordova registry.

o url: A URL starting with https:// or git://, pointing to a valid git repository that is clonable and contains a plugin.xml file. The contents of this repository would be copied into the --plugins_dir.

o path: A path to a directory containing a valid plugin which includes a plugin.xml file. This path's contents will be copied into the --plugins_dir.

· --uninstall: Uninstalls an already---install'ed plugin from a cordova project. Specify the plugin ID.

Other parameters:

· --plugins_dir defaults to <project>/cordova/plugins, but can be any directory containing a subdirectory for each fetched plugin.

· --www defaults to the project's www folder location, but can be any directory that is to be used as cordova project application web assets.

· --variable allows to specify certain variables at install time, necessary for certain plugins requiring API keys or other custom, user-defined parameters. Please see the plugin specificationfor more information.

3 源码中API接口

(1)install method

module.exports = function installPlugin(platform, project_dir, id, plugins_dir, subdir, cli_variables, www_dir, callback) {

Installs a plugin into a specified cordova project of a specified platform.

· platform: one of android, ios, blackberry10, wp7 or wp8

· project_dir: path to an instance of the above specified platform's cordova project

· id: a string representing the id of the plugin, a path to a cordova plugin with a validplugin.xml file, or an https:// or git:// url to a git repository of a valid cordova plugin or a plugin published to the Cordova registry

· plugins_dir: path to directory where plugins will be stored, defaults to<project_dir>/cordova/plugins

· subdir: subdirectory within the plugin directory to consider as plugin directory root, defaults to .

· cli_variables: an object mapping cordova plugin specification variable namess (see plugin specification) to values

· www_dir: path to directory where web assets are to be copied to, defaults to the specified project directory's www dir (dependent on platform)

callback: callback to invoke once complete. If specified, will pass in an error object as a first parameter if the action failed. If not and an error occurs, plugman will throw the error

(2)uninstall method

module.exports = function uninstallPlugin(platform, project_dir, id, plugins_dir, cli_variables, www_dir, callback) {

Uninstalls a previously-installed cordova plugin from a specified cordova project of a specified platform.

· platform: one of android, ios, blackberry10, wp7 or wp8

· project_dir: path to an instance of the above specified platform's cordova project

· id: a string representing the id of the plugin

· plugins_dir: path to directory where plugins are stored, defaults to<project_dir>/cordova/plugins

· subdir: subdirectory within the plugin directory to consider as plugin directory root, defaults to .

· cli_variables: an object mapping cordova plugin specification variable namess (see plugin specification) to values

· www_dir: path to directory where web assets are to be copied to, defaults to the specified project directory's www dir (dependent on platform)

· callback: callback to invoke once complete. If specified, will pass in an error object as a first parameter if the action failed. If not and an error occurs, plugman will throw the error

(3)fetch method

Copies a cordova plugin into a single location that plugman uses to track which plugins are installed into a project.

module.exports = function fetchPlugin(plugin_dir, plugins_dir, link, subdir, git_ref, callback) {

· plugin_dir: path, URL to a plugin directory/repository or name of a plugin published to the Cordova registry.

· plugins_dir: path housing all plugins used in this project

· link: if plugin_dir points to a local path, will create a symbolic link to that folder instead of copying into plugins_dir, defaults to false

· subdir: subdirectory within the plugin directory to consider as plugin directory root, defaults to .

· gitref: if plugin_dir points to a URL, this value will be used to pass into git checkout after the repository is cloned, defaults to HEAD

· callback: callback to invoke once complete. If specified, will pass in an error object as a first parameter if the action failed. If not and an error occurs, plugman will throw the error

(4)prepare method

Finalizes plugin installation by making configuration file changes and setting up a JavaScript loader for js-module support.

module.exports = function handlePrepare(project_dir, platform, plugins_dir) {

· project_dir: path to an instance of the above specified platform's cordova project

· platform: one of android, ios, blackberry10, wp7 or wp8

· plugins_dir: path housing all plugins used in this project

4 插件目录结构

foo-plugin/

|- plugin.xml     # xml-based manifest

|- src/           # native source for each platform

|  |- android/

|  |  `- Foo.java

|  `- ios/

|     |- CDVFoo.h

|     `- CDVFoo.m

|- README.md

`- www/

   |- foo.js

   `- foo.png



    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3