第八届ACM趣味程序设计竞赛第四场(正式赛)A B C

周日刚打算午觉躺下,舍友说今天有比赛,就凑个热闹..


A - Picking&Dancing

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)
 

Yitong_Qin and Xiaoyu_Chen are playing a game.There are $N$ stones placed on the ground,forming a sequence.

Thr stones are labeled from 1 to N. Yitong_Qin and Xiaoyu_Chen in turns take exactly two consecutive stones on the ground 

until there are no consecutive stones on the ground.That is,each player can take stone $i$ and stone $i+1$,

where $1 \leq i \leq n-1$.If the number of stones left is odd,Yitong_Qin wins ,so Xiaoyu_Chen has to dance.

Otherwise Xiaoyu_Chen wins Yitong_Qin has to dance.

Input

The input contains an integer $N(1 \leq N \leq 5000)$,the number of stones.

Output

Output the guy has to dance.

Sample input and output

Sample Input Sample Output
1
Xiaoyu_Chen
2
Yitong_Qin
5
Xiaoyu_Chen

Source



Solution

  1. Q 和C依次取两个剩下是奇数1的话C跳舞,偶数0的话Q跳舞
  2. 取模判定即可
#include<iostream>
using namespace std;
int main(void)
{
	int n;
	cin >> n;

	if (n % 2 == 1)
		cout << "Xiaoyu_Chen";
	else
		cout << "Yitong_Qin";
	return 0;
}
VC++6.0编译测试结果:  



/* -----------------------------------------------分隔符---------------------------------------------------------------*/


B - string

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)
 

A string consisting of lowercase letters,two adjacent character can be combined if and only if this two character are different.

And the combined character is the latter one. (such as "ac" can be combined, and the result is "a").

Now your work is to combined the character as more as possible so that finally the string can be shortest.

Input

A string consisting of lowercase letters.  (1length200000) (1≤length≤200000)

Output

a positive integer x means the finally length of string.

Sample input and output

Sample Input Sample Output
abcd
1
aac
2

Solution

  1. 前后两个字母融合等于前面的字母,按顺序走,说明最关键的就是一开始的那个字母
  2. 若输入字母为“aabcadaa”,则输出为2,因为即使b之后还有a
    但是从b往后的字母都可以被b融合,得到aab,最后留下aa;
  3. 所以答案就是连续的开头字母个数 //fgets用来输入字符串,而l的长度比字符长度多1
#include<iostream>
#include<string.h>
using namespace std;
#define N 200000
char a[N];
int main(void)
{
	int i, l, s=1;
	fgets(a, N + 1, stdin);
	l = strlen(a);
	for (i = 0; i < l-1; i++)
	{
		if (a[i] == a[i + 1])
		{
			s++;
		}
		else
		{
			break;
		}
	}
	cout << s;
	return 0;
}

VC++6.0编译测试结果:


/* -----------------------------------------------分隔符---------------------------------------------------------------*/


C - How To Get Twenty-four?

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)
 

It is nearly the December 7, Mr.Flower's birthday. His roommates have already prepared a precious gift for him. 

But they have a simple exam for Mr.Flower, only if he get the answer can he receive the gift. The question is described as follow:

  1. Mr.Flower's roommates will give him a integer N, that means he get N '7', for example if N=4, Mr.Flower get '7','7','7','7';

  2. Then Mr.Flower should ues these number to calculate '24';

  3. Mr.Flower could only ues '+', '-', '*', '(' , ')' and '/';

This problem is very easy for Mr.Flower, but he should prepare for CET-6. 

You are the best friend of Mr.Flower, so he wants you to tell him whether he can get '24'.

Input

there is one numbers $N$, the number of '7' that you have$(1 \leq N \leq 1000)$.

Output

if you can get '24' with N '7',than output "YES"(without quote), if you can't do it, output "NO".

Sample input and output

Sample Input Sample Output
1
NO
2
NO
6
YES

Hint

对于样例三  (7×7×77)/(7+7)=24

Solution

  1.   已知无法构成由7的个数小于等于5,通过加减乘除组成一个24点的情况
  2. 6个7的情况Hint有说明(称之为6式)
  3. 7个7的情况,拼凑得:“7+7+7+(7+7+7)/7 ”
  4. 由6式衍生出8个7的情况即:“6式+(7-7)”
  5. 在衍生出9个及其以上的情况“6式+(7-7)/(7..)”
  6. 所以,只要n的个数超过6个,n个7通过加减乘除可得到24
#include<iostream>
using namespace std;
int main(void)
{
	int n;
	cin >> n;
	if (n >= 6)
		cout << "YES";
	else 
		cout << "NO";

	return 0;
}
VC++6.0编译测试结果:

/* -----------------------------------------------分隔符---------------------------------------------------------------*/
/*yzw 2016年12月18日20:15:20*/





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
java编程100实例,适合初学java的朋友学习,含有源代码,省去了码代码的时间,可以直接导入,运行。建议实用eclipse,内容如下: 实例1 产生自己的控件 实例2 控件的排布示例 实例3 控件的相互控制与消息传递 实例4 彩色列表框 实例5 圆形的按钮 实例6 密码验证框 实例7 虚线与实线 实例8 显示多种字体 实例9 多种风格的窗口 实例10右键弹出菜单 实例11 森林状的关系图 实例12 简单的文本编辑器 实例13使用剪贴板的复制粘贴程序 实例14 文本的拖动处理 实例15 图片的拖动处理 实例16 数字时钟 实例17 简单的表单程序 实例18动画图标 实例19 滑杆演示 实例20程序启动界面 实例21 调色板 实例22 文件选择器 实例23 自定义光标 实例24 HTML浏览器 实例25抖动文字 实例26 阴影文字 实例27 3D文字 实例28 波浪文字 实例29 飞行文字 实例30 伸展文字 实例31 用Applet显示图片 实例32 图片火焰效果 实例33 图片百叶窗 实例34 图片倒影 实例35 图片翻折 实例36 闹钟 实例37 万年历 实例38 计算器 实例39 电子相册 实例40 声音播放程序 实例41 视频播放程序 实例42 半透明图片 实例43 图片旋转 实例44缩小与放大 实例45 移动的遮照效果 实例46 模糊与锐化 实例47 常用图形的绘制与填充 实例48 不规则图形的绘制 实例49 列出目录下的文件 实例50 取得目录文件信息 实例51 目录和文件的创建、删除和更名 实例52 复制文件 实例53 用GZIP压缩解压文件 实例54 用Zip压缩多个文件 实例55 从压缩包中提取文件 实例56 zip压缩包查看程序 实例57 压缩中文文件名的文件 实例58 存储与读取对象 实例59 Java画图程序 实例60 从网络取得图像 实例61 从网络取得文件 实例62 TCP服务器端 实例63 TCP客户端 实例64 UDP服务器模型 实例65 UDP客户端模型 实例66 聊天室服务器 实例67 聊天室客户端 实例68 组播组中发送和接受数据 实例69 时间日期服务器 实例70 FTP连接与浏览 实例71 HTTP连接与浏览 实例72 数据压缩与传输 实例73 Telnet客户端 实例74 创建和配置数据源 实例75 建立与断开数据库的连接 实例76 查询数据库 实例77 使用表格显示查询结果 实例78 修改数据库 实例79 创建与删除数据库中的表 实例80 Servlet中连接数据库 实例81 留言板程序 实例82 客户登录Servlet小程序 实例83 访问权限控制 实例84 产生密钥 实例85 对称加密 实例86 非对称加密 实例87 数字签名 实例88 数字证书 实例89SSL及HTTPS协议 实例90 Screen小程序 实例91 文字跑马灯与信息窗口 实例92 手机日历 实例93 手机画册 实例94Canvas绘图程序 实例95 碰撞的小球 实例96 用RMS记录个人信息 实例97 建立Http连接 实例98 从网络上下载数据 实例99定时器的使用 实例100 音乐播放
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值