当前位置: 首页 > 编程日记 > 正文

[置顶]2010年东北大学ACM程序设计竞赛冬季校赛题解

8题只做出4题比较easy的题,而且做得挺麻烦,看来还要多练练。

AC的题如下

NEUOJ  1112 I Love Apple

Description
So many people love apple and there is a problem about apple.

An Apple Word is a word that consists of only the letters A, P, L, and E, in that exact relative order. There must be exactly one A, two or more Ps, exactly one L and exactly one E. Case does not matter.

For example, "Apple" and "apPpPPlE" are Apple Words, while "APLE", "Apples", "Aplpe" and "coconut" are not.  You are given a string word which you must turn into an Apple Word. For each character in word, you can either replace it with a different letter or leave it unchanged. No other operations, like inserting new characters or deleting existing characters, are allowed.

Please find the minimal number of characters you must replace to get an Apple Word. If it's impossible, output -1.
Input
There're multiple test cases.
Each case is a string contain between 1 and 50 characters, inclusive.
Each character in input string will be an uppercase letter ('A'-'Z') or a lowercase letter ('a'-'z').
Output
For each case, output the minimal number of characters you must replace to get an Apple Word, If it's impossible, output -1
Sample Input
apPpPPlE
APLE
NEUAcmer
Sample Output
0
-1
8
Hint
Source
2010年东北大学ACM程序设计竞赛冬季校赛
#include <iostream> #include <cstring> using namespace std; //判断是否是appleword bool isappleword(char * s){ bool flag = false; if((s[0] == 'a' || s[0] == 'A') && (s[1] == 'p' || s[1] == 'P') && (s[2] == 'p' || s[2] == 'P')) { int len = strlen(s); if ((s[len-1] == 'e' || s[len-1] == 'E') && (s[len-2] == 'l' || s[len-2] == 'L')){ flag = true; for (int i = 2;i<=len-3;i++) { if (s[i] != 'P' && s[i] != 'p') { flag = false; } } } } if (flag) { return true; } return false; } int main(){ char s[60]; bool flag; int len; int changenum; int i; while (scanf("%s",s) != EOF) { flag = isappleword(s); len = strlen(s); if (flag) { cout<<0<<endl; flag = false; continue; } else if(len < 5){ cout<<-1<<endl; continue; } else{ changenum = 0; if (s[0] != 'a' && s[0] != 'A') { s[0] = 'a'; changenum++; } if (s[1] != 'p' && s[1] != 'P') { s[1] = 'p'; changenum++; } if (s[2] != 'p' && s[2] != 'P') { s[2] = 'p'; changenum++; } if (s[len-1] != 'e' && s[len-1] != 'E') { s[len-1] = 'e'; changenum++; } if (s[len-2] != 'l' && s[len - 2] != 'L') { s[len-2] = 'l'; changenum++; } for (i = 3;i < len-2 ;i++) { if (s[i] != 'p' && s[i] != 'P') { s[i] = 'p'; changenum++; } } cout<<changenum<<endl; changenum = 0; } } return 0; }
Problem 1114 - A Easy Problem
Description
Risk is a board game played on a world map. This world is divided into regions by borders.
Each region is controlled by a player (either you or one of your opponents). Any region that
you control contains a positive number of your armies.
In each turn, you are allowed to move your armies. Each of your armies may either stay
where it is, or move from a region to a bordering region under your control. The movements
are performed one by one, in an order of your choice. At all times, each region must contain
at least one army.
For strategic purposes, it is important to move your armies to regions that border your
opponents’ regions and minimize the number of armies on your regions that are totally surrounded
by other regions under your control. You want your weakest link, i.e., the border
region with the minimum number of armies, to be as strong as possible. What is the maximum
number of armies that can be placed on it after one turn?
Input
On the first line a positive integer: the number of test cases, at most 100. After that per test
case:
  One line with an integer n (1 <= n <= 100): the number of regions.
  One line with n integers ai (0 <= ai <= 100): the number of your armies on each region.
A number 0 indicates that a region is controlled by your opponents, while a positive
number indicates that it is under your control.
  n lines with n characters, where each character is either ‘Y’ or ‘N’. The i-th character
of the j-th line is ‘Y’ if regions i and j border, and ‘N’ otherwise. This relationship is
symmetric and the i-th character of the i-th line will always be ‘N’.
In every test case, you control at least one region, and your opponents control at least
one region. Furthermore, at least one of your regions borders at least one of your opponents’
regions.
Output
Per test case:
  One line with an integer: the maximum number of armies on your weakest border
region after one turn of moving.
Sample Input
2
3
1 1 0
NYN
YNY
NYN
7
7 3 3 2 0 0 5
NYNNNNN
YNYYNNN
NYNYYNN
NYYNYNN
NNYYNNN
NNNNNNY
NNNNNYN
Sample Output
1
4
Hint
Source
2010年东北大学ACM程序设计竞赛冬季校赛
#include <iostream> using namespace std; int sqnum[105]; int score[10005] = {0}; int dafen(int num){ int i,j; int s=0; for (i = 0;i < 101;i++) for (j = i;j < 101;j++) { if (sqnum[i] + sqnum[j] == num) s++; } return s; } int main(){ //先打表,0-10000的平方数 int i,j=0; int n , l,r; for (i =0 ; i*i <=10000;i++) { sqnum[j++] = i*i; } cin >> n; while (n--) { cin>>l>>r; //对l-r之间的每个数都进行打分存于数组中 for (i = l;i<=r;i++) { score[i] = dafen(i); } //在score中找最大的分数 int temp = score[0]; for(i = l;i<=r;i++){ if (score[i] > temp) { temp = score[i]; } } for (i=r;i>=l;i--) { if (score[i] == temp) { cout<< i<<endl; break; } } } return 0; }
Problem 1116 - Double Xor
Description
once upon a time, there is a very strange computer. Its memory consists of several bits, each initially set to 0, and it can only perform the following type of operation:

Choose one of the bits in memory, and choose a value - 0 or 1. All the bits between the selected bit and the last bit in memory, inclusive, will be set to the chosen value.

For example, if the memory is "0010", and you choose the second bit and a value of 1, the memory will change to "0111".  You are given a string mem.

The number of characters in mem is equal to the number of bits in the computer's memory. Compute the minimum number of operations required to set the computer's memory equal to mem.
Input
There're multiple test cases.
Each case contain a string which is mem. It will contain only the characters '0' (zero) or '1' (one) and between 1 and 50 characters, inclusive.
Output
For each test cases only a integer indicate the minimum times of operations required to set the computer's memory equal to mem.
Sample Input
0100
111000111
Sample Output
2
3
Hint
Source
2010年东北大学ACM程序设计竞赛冬季校赛
#include <iostream> #include <cstring> using namespace std; bool strcmpyang(char *targets1,char *mems2){ int len = strlen(targets1); bool equalflag = true; for (int i = 0;i < len;i++) { if (targets1[i] != mems2[i]) { equalflag = false; } } return equalflag; } int main(){ char targetmem[50]; char mem[50]; int i,j,times,len,pre; while (scanf("%s",targetmem) != EOF) { len = strlen(targetmem); memset(mem,'0',len); times = 0; pre = 0; while (!strcmpyang(targetmem,mem)) { times++; if (times%2 == 1) { for (i = pre;i < len; i++) { if (targetmem[i] == '1'){ pre = i; break; } } for (j = i;j<len;j++) { mem[j] = '1'; } } if (times%2 == 0) { for (i = pre;i < len; i++) { if (targetmem[i] == '0'){ pre = i; break; } } for (j = i;j<len;j++) { mem[j] = '0'; } } } cout<<times<<endl; } return 0; }
Problem 1117 - Strange Computer
Description
once upon a time, there is a very strange computer. Its memory consists of several bits, each initially set to 0, and it can only perform the following type of operation:

Choose one of the bits in memory, and choose a value - 0 or 1. All the bits between the selected bit and the last bit in memory, inclusive, will be set to the chosen value.

For example, if the memory is "0010", and you choose the second bit and a value of 1, the memory will change to "0111".  You are given a string mem.

The number of characters in mem is equal to the number of bits in the computer's mem ory. Compute the minimum number of operations required to set the computer's memory equal to mem.
Input
There're multiple test cases.
Each case contain a string which is mem. It will contain only the characters '0' (zero) or '1' (one) and between 1 and 50 characters, inclusive.
Output
For each test cases only a integer indicate the minimum times of operations required to set the computer's memory equal to mem.
Sample Input
0100
111000111
Sample Output
2
3
Hint
Source
2010年东北大学ACM程序设计竞赛冬季校赛
#include <iostream> #include <cstring> using namespace std; bool strcmpyang(char *targets1,char *mems2){ int len = strlen(targets1); bool equalflag = true; for (int i = 0;i < len;i++) { if (targets1[i] != mems2[i]) { equalflag = false; } } return equalflag; } int main(){ char targetmem[50]; char mem[50]; int i,j,times,len,pre; while (scanf("%s",targetmem) != EOF) { len = strlen(targetmem); memset(mem,'0',len); times = 0; pre = 0; while (!strcmpyang(targetmem,mem)) { times++; if (times%2 == 1) { for (i = pre;i < len; i++) { if (targetmem[i] == '1'){ pre = i; break; } } for (j = i;j<len;j++) { mem[j] = '1'; } } if (times%2 == 0) { for (i = pre;i < len; i++) { if (targetmem[i] == '0'){ pre = i; break; } } for (j = i;j<len;j++) { mem[j] = '0'; } } } cout<<times<<endl; } return 0; }

转载于:https://www.cnblogs.com/yangliu/archive/2010/12/12/2298459.html

相关文章:

生成唯一序列号

写一个存储过程来实现&#xff1a; 转载于:https://www.cnblogs.com/hwgok/p/8136750.html

如何改变一个地图的Zoom单位

mapControl1.Map.Zoom new MapInfo.Geometry.Distance(mapControl1.Map.Zoom.value,MapInfo.Geometry.DistanceUnit.Kilometer);也可以分开写成如下格式&#xff1a;MapInfo.Geometry.Distance d new MapInfo.Geometry.Distance(1000, DistanceUnit.Kilometer);mapControl1.M…

canvas上的像素操作(图像复制,细调)

canvas上的像素操作(图像复制&#xff0c;细调) 总结 1、操作对象&#xff1a;ImageData 对象&#xff0c;其实是canvas的像素点集合 2、主要操作&#xff1a; var objctx.getImageData(0,0,100,100); ctx.putImageData(obj,110,0) 3、操作图片要放在站点才能正常操作&#xf…

sql查询返回xml数据之应用【转载】

sql查询返回xml数据之应用【转载】 今天查看邮件&#xff0c;看到一标题Using the FOR XML Clause to Return Query Results as XML&#xff0c;点进去看了看&#xff0c;以前也是知道sql server 查询可以返回xml格式&#xff0c;但具体一到应用中比较少&#xff0c;读过文章后…

solr 实现对经纬度的查询

1、solr版本 solr7 2、solr 经纬度查询的方式 使用LatLonType(用于平面坐标&#xff0c;而不是大地坐标&#xff09;SpatialRecursivePrefixTreeFieldType&#xff08;缩写为RPT&#xff09;BBoxField&#xff08;用于边界索引查询&#xff09;2.1 使用 LatLonPointSpatialF…

win7关于IIS发布网站时候数据库的问题,xp也一样

Win7装iis极其简单. 添加ASP.NET网站时应该选择添加"添加应用程序" 如果要连接sql server会报错,说是 "无法打开登录所请求的数据库 "MarketDept"。登录失败。用户 IIS APPPOOL\DefaultAppPool 登录失败。" 而系统中根本不会存在这个用户的. 解决…

Linq 等式运算符:SequenceEqual

检查元素的数量&#xff0c;每个元素的值及两个集合中元素的顺序是否相等,3个方面都相等则为true,否则为false IList<string> strList1 new List<string>(){"One", "Two", "Three", "Four", "Three"};IList<…

Swing 实现聊天系统 私发与群发

该系统使用的了socket、swing相关知识&#xff0c;实现了一个简单的群聊和私聊的系统。 1、程序界面功能展示 服务端swing界面展示 客户端服务展示 用户上线与发送消息客户端与服务端 私发消息 相关代码&#xff1a; package frame;import java.awt.BorderLayout; import ja…

Http和Socket连接区别(ZT)

1、TCP连接 要想明白Socket连接&#xff0c;先要明白TCP连接。手机能够使用联网功能是因为手机底层实现了TCP/IP协议&#xff0c;可以使手机终端通过无线网络建立TCP连接。TCP协议可以对上层网络提供接口&#xff0c;使上层网络数据的传输建立在“无差别”的网络之上。 建立起一…

函数传参涉及到副本的创建与拷贝问题分析

遇到一个问题,是这样的: b [1, 2, 3]def aaa(b):b.append(4)def bbb(b):b 5aaa(b) print(b) # [1, 2, 3, 4]bbb(b) print(b) # [1, 2, 3, 4] 为什么呢,为什么通过函数传参,去修改参数,结果不一致呢? 原因是因为函数传参涉及到了参数副本的创建与拷贝,具体详解: 圆圈2为传参…

网页鼠标滚动实现图片缩放

<SCRIPT LANGUAGE"JavaScript"><!--//图片按比例缩放,可输入参数设定初始大小function resizeimg(ImgD,iwidth,iheight) {var p_w_picpathnew Image();p_w_picpath.srcImgD.src;if(p_w_picpath.width>0 && p_w_picpath.height>0){if(p_w_picp…

Dubbo 2.7.1 踩坑记

Dubbo 2.7 版本增加新特性&#xff0c;新系统开始使用 Dubbo 2.7.1 尝鲜新功能。使用过程中不慎踩到这个版本的 Bug。 系统架构 Spring Boot 2.14-Release Dubbo 2.7.1 现象 Dubbo 服务者启动成功&#xff0c;正常提供服务&#xff0c;消费者调用偶现失败的情况。错误如下图: …

经典算法研究系列:二、Dijkstra 算法初探

经典算法研究系列&#xff1a;二、Dijkstra 算法初探 July 二零一一年一月 本文主要参考&#xff1a;算法导论 第二版、维基百科。 写的不好之处&#xff0c;还望见谅。本经典算法研究系列文章&#xff0c;永久勘误&#xff0c;永久更新、永久维护。 July、二零一一年二月…

[Python Study Notes] Python的安装

Windows&#xff1a; 1.下载安装包&#xff1a; 转到Python官网https://www.python.org/downloads/ &#xff0c;下载最新版本的Python。 2.安装 安装到自定义的安装路径下。 3.配置环境变量 安装完成后--》【右键快捷方式】--》【复制python路径】&#xff0c;例如&#xff1…

swing 实现电影选座系统

该系统使用swing数据库 实现一个电影选座系统&#xff0c;相关系统的截图如下 使用三层架构实现电影购票系统&#xff0c;分用户和管理员&#xff0c;用户功能:展示电影&#xff0c;查找电影(模糊查询)&#xff0c;查看电影详情&#xff0c;查找场次&#xff0c;购买影票&…

JS动态加载JS

1、直接document.write <script language"javascript"> document.write("<script srctest.js><\/script>"); </script> 2、动态改变已有script的src属性 <script src id"s1"></script> <script lang…

PAT乙级1037

1037 在霍格沃茨找零钱 (20 分)如果你是哈利波特迷&#xff0c;你会知道魔法世界有它自己的货币系统 —— 就如海格告诉哈利的&#xff1a;“十七个银西可(Sickle)兑一个加隆(Galleon)&#xff0c;二十九个纳特(Knut)兑一个西可&#xff0c;很容易。”现在&#xff0c;给定哈利…

SAD和SATD的区别[摘]

Q:如果不用率失真最优化&#xff0c;为什么选择SATD&#xff0b;deltar&#xff08;mv&#xff0c;mode&#xff09;作为模式选择的依据&#xff1f;为什么运动估计中&#xff0c;整象素搜索用SAD&#xff0c;而亚象素用SATD&#xff1f;为什么帧内模式选择要用SATD&#xff1f…

照片换色 使用Python 或者 java

记录使用第三方api 给照片换底色&#xff0c;智能抠图。 1、第三方接口地址 https://www.remove.bg/api 2、抠图效果 3、使用python 实现的代码 在网页换色是不需要进行注册的&#xff0c;如果自己开发 需要注册账号 &#xff0c;得到调取api的口令 import requests impor…

WEB安全,SQL注入漏洞的加固代码汇总

该修复任务专用于处理以下安全性问题&#xff1a;[1] SQL 盲注[2] SQL 注入[3] XPath 注入[4] 发现数据库错误模式[5] 跨站点脚本编制[6] 使用 SQL 注入的认证旁路[7] HTTP 响应分割[8] 链接注入&#xff08;便于跨站请求伪造&#xff09;详细信息若干问题的补救方法在于对用户…

mui ios中form表单中点击输入框头部导航栏被推起及ios中form表单中同时存在日期选择及输入框时,日历选择页面错乱bug...

一、ios header导航栏被推起解决方法 1 设置弹出软键盘时自动改变webview的高度 plus.webview.currentWebview().setStyle({ softinputMode: "adjustResize" // 弹出软键盘时自动改变webview的高度 }); 2 增加样式 html, body { height: 100%; margin: 0px; …

qt试用1(Eclipse+cdt+Qt)

下载eclipse-cpp-helios-SR1-win32.zip下载Qt下载qt-eclipse-integration-win32-1.6.1.exe写一个启动eclipse的batch文件C:\program\eclipse-cpp-helios-SR1-win32\eclipse\cdt.batset path%path%;C:\Qt\2010.05\mingw\binset LIBRARY_PATHC:\Qt\2010.05\mingw\libset C_INCLUD…

Solr 中遇到的问题

1、问题1 &#xff1a;whose UTF8 encoding is longer than the max length 32766 Error from server at http://localhost:8983/solr/newcore: Exception writing document id 995 to the index; possible analysis error: Document contains at least one immense term in f…

【推荐】Flex+asp.net上传文件

前台Flex文件&#xff1a;UploadSample.mxml&#xff0c;其代码如下所示&#xff1a; 1 <?xml version"1.0" encoding"utf-8"?>2 <mx:Application xmlns:mx"http://www.adobe.com/2006/mxml"layout"absolute">3 <mx:…

Centos查找命令清单

查找目录&#xff1a;find /&#xff08;查找范围&#xff09; -name 查找关键字 -type d查找文件&#xff1a;find /&#xff08;查找范围&#xff09; -name 查找关键字 -print 如果需要更进一步的了解&#xff0c;可以参看Linux的命令详解。 这里摘抄如下&#xff1a; find …

docker 安装使用 solr

目录 1、安装solr 7.5 2、启动solr服务 2.1 创建一个solr库 3、配置IK分词器 4、docker 配置solr登录密码 1、安装solr 7.5 docker solr 官网&#xff1a;https://hub.docker.com/_/solr/ docker pull solr:7.5.0 2、启动solr服务 docker run --name my_solr -d -p 898…

2010中国城市GDP排名

1、上海市 14900.93亿元 8.2&#xff05; 上海 2、北京市 11865.9亿元 10.1% 北京 3、广州市 9118.6亿元 11% 广东1 4、深圳市 8245亿元 10.5% 广东2 5、天津市 7500亿元 16.5% 天津 6、苏州市 7400亿元 11% 江苏1 7、重庆市 5856亿元 14.9% 重庆 8、杭州市 5098.66亿元 10% 浙…

基于wsimport生成代码的客户端

概述 wsimport是jdk自带的命令&#xff0c;可以根据wsdl文档生成客户端中间代码&#xff0c;基于生成的代码编写客户端&#xff0c;可以省很多麻烦。wsimport命令 wsimport的用法 wsimport [options] <WSDL_URI>比较常用的[options]有&#xff1a;1. -d <directory>…

C# Trim 的使用

C# 移除字符 /// <summary> /// 删除指定字符 /// </summary> /// <returns>返回经过修饰的字符串</returns> private string DelChar() { string mess " Test Program "; // 测试字符 if (mess ! string.Empty) …

CSS截取字符串,兼容浏览器

今天在经典论坛看到有同学问到CSS截取字符多余省略号代替的求助且要兼容FF... 这个的确是个比较头痛的问题&#xff0c;现在我在的公司都是程序截取显示省略符的。兼容是没问题&#xff0c;但在中文和数学或字母混排时&#xff0c;就会有点小小的视觉缺陷。在程序截取中&#x…