A. Arpa’s hard exam and Mehrdad’s naive cheat

题意:统计1378^n的末尾数字

即统计8^n的末尾数字

n=0时为1

其他情况为{8,4,2,6}中的一个

#include <stdio.h>

const int ans[4] = { 6, 8, 4, 2 };

int main() {
	static int n;

	scanf("%d", &n);
	if (n == 0) printf("1\n");
	else printf("%d\n", ans[n % 4]);

	return 0;
}

B. Arpa’s obvious problem and Mehrdad’s terrible solution

题意:给个数列a1...an和一个数x,问有多少对i,j(i < j)使 a[i] xor a[j] == x

记录每个每个数字出现在a数列中的次数,从而统计答案

注意开数组的范围

#include <stdio.h>

const int kMaxn = 200010;

int n, x, a[kMaxn], b[kMaxn];
long long ans;

int main() {
	static int i;

	scanf("%d%d", &n, &x);
	memset(b, 0, sizeof(b));
	for (i = 1; i <= n; ++i) {
		scanf("%d", a + i);
		++b[a[i]];
	}
	ans = 0;
	for (i = 1; i <= n; ++i) {
		if ((a[i] ^ x) == a[i])
			ans += b[a[i]] - 1;
		else
			ans += b[a[i] ^ x];
	}
	printf("%I64d\n", ans >> 1);

	return 0;
}

C. Vladik and flights

题意:在s[i] == s[j]时从i到j话费为0,否则为|i-j|,问从a到b最小花费

结果最大为1

s[a]==s[b]答案即为0,否则为1

#include <stdio.h>

const int kMaxn = 100010;

int n, a, b;
char s[kMaxn];

int main() {
	static int i, ans;

	scanf("%d%d%d", &n, &a, &b);
	scanf(" %s", s + 1);
	if (s[a] == s[b])
		puts("0");
	else
		puts("1");

	return 0;
}

D. Chloe and the sequence

题意:给你一个构造方案[1]->[1,2,1]->[1,2,1,3,1,2,1]->[1,2,1,3,1,2,1,4,1,2,1,3,1,2,1]......问操作n-1步后数列的第k个位置是什么数字

以[1,2,1,3,1,2,1,4,1,2,1,3,1,2,1]为例,

先判断k的位置在4上  :输出结果

      还是4左边:删掉4和4右边的数列

      还是4右边:和左边是对称的,k=总长度减k,然后和左边一样处理

再类似判断3,2,1

#include <stdio.h>

int n;
long long k;

int main() {
	static int i;
	static long long tmp;

	scanf("%d%I64d", &n, &k);
	for (i = n; i >= 1; --i) {
		tmp = (1LL << i);
		//printf("%I64d %I64d\n", k, tmp);
		if (k == tmp) {
			printf("%d\n", i + 1);
			return 0;
		} else if (k > tmp)
			k -= tmp;
	}
	printf("1\n");

	return 0;
}

E. Vladik and fractions

题意:求构造2/n = 1/x + 1/y + 1/z,x,y,z为不一样的整数

n,n+1,n*(n+1)

#include <stdio.h>

long long n;

int main() {
	static long long i, k, x, y, d;

	scanf("%I64d", &n);
	if (n == 1)
		puts("-1");
	else
		printf("%I64d %I64d %I64d\n", n, n + 1, n * (n + 1));

	return 0;
}

F. Compote

看懂题就能做出来。

#include <stdio.h>

int a, b, c;

int main() {
	static int i;

	scanf("%d%d%d", &a, &b, &c);
	b /= 2;
	c /= 4;
	printf("%d\n", std::min(std::min(a, b), c) * 7);

	return 0;
}

G. Decoding

题意:给个操作,每次去掉中间的字符,现有去掉字符的顺序,求原字符串

#include <stdio.h>

int n;
char s[2222], ans[2222];

int main() {
	static int i, mid;

	scanf("%d", &n);
	scanf(" %s", s + 1);
	mid = (n >> 1) + (n & 1);
	ans[mid] = s[1];
	for (i = 2; i <= n; ++i) {
		if (n & 1)
			ans[mid + (i & 1 ? (i >> 1) : -(i >> 1))] = s[i];
		else
			ans[mid + (i & 1 ? -(i >> 1) : (i >> 1))] = s[i];
	}
	for (i = 1; i <= n; ++i)
		putchar(ans[i]);

	return 0;
}

H. Tram

题意:有列车在一条直线上往返,已知列车的起始位置,方向,速度,人的初始位置,目标位置,步行速度,求人还要多久才能到达目的地

人要么走到目的地,要么坐车到目的地,比较车第一次经过人然后到目的地的时间与人直接走过去的时间,去较小者即可。

#include <stdio.h>
#include <algorithm>

int s, x1, x2, t1, t2, p, d, ans;

inline int myabs(int x) {
	return x > 0 ? x : -x;
}

int main() {
	static int i;

	scanf("%d%d%d", &s, &x1, &x2);
	scanf("%d%d", &t1, &t2);
	scanf("%d%d", &p, &d);
	if (t2 <= t1)
		printf("%d\n", myabs(x2 - x1) * t2);
	else {
		ans = 0;
		i = 0;
		while (!i || p != x2) {
			if (p == x1) i = 1;
			p += d;
			ans += t1;
			if (p == 0 || p == s) d = -d;
		}
		ans = std::min(ans, myabs(x2 - x1) * t2);
		printf("%d\n", ans);
	}

	return 0;
}

I. Green and Black Tea

题意:给G的个数,B的个数,G与B最长连续不能长于k,求构造方案

把G与B较小的找到,把较多的字母分为(较小的数的个数+1)段,每段尽量平均。

#include <stdio.h>
#include <algorithm>

int n, k, a, b, m;
char op;

inline int myabs(int x) {
	return x > 0 ? x : -x;
}

int main() {
	static int i, j;

	scanf("%d%d%d%d", &n, &k, &a, &b);
	op = 1;
	if (a < b) {
		op = 0;
		std::swap(a, b);
	}
	m = a / (b + 1);
	a %= (b + 1);
	if (m + (a > 0) > k)
		puts("NO");
	else {
		for (j = 1; j <= m + (a > 0); ++j)
			putchar(op ? 'G' : 'B');
		--a;
		for (i = 1; i <= b; ++i) {
			putchar(op ? 'B' : 'G');
			for (j = 1; j <= m + (a > 0); ++j)
				putchar(op ? 'G' : 'B');
			--a;
		}
	}

	return 0;
}

HIT Winter Day ACM入门的更多相关文章

  1. 大牛对ACM入门菜鸟的一些话

    首先就是我为什么要写这么一篇日志.原因很简单,就是因为前几天有个想起步做ACM人很诚恳的问我该如何入门.其实就现在而言,我并不是很想和人再去讨论这样的话题,特别是当我发现我有很多的东西要学的时候,我实 ...

  2. ACM 入门计划

    acm 本文由swellspirit贡献 ACM • I can accept failure. but I can't accept not trying. Life is often compar ...

  3. ACM入门步骤(一)

    一般的入门顺序: 0. C语言的基本语法(或者直接开C++也行,当一个java选手可能会更受欢迎,并且以后工作好找,但是难度有点大),[参考书籍:刘汝佳的<算法竞赛入门经典>,C++入门可 ...

  4. ACM入门指南

    本文已经转移到了:http://harryguo.me/2015/11/03/ACM-%E5%85%A5%E9%97%A8%E6%8C%87%E5%8D%97/ 什么是ACM? 想必打开这篇博客的人已 ...

  5. acm入门 杭电1001题 有关溢出的考虑

    最近在尝试做acm试题,刚刚是1001题就把我困住了,这是题目: Problem Description In this problem, your task is to calculate SUM( ...

  6. ACM入门之OJ~

    所谓OJ,顾名思义Online Judge,一个用户提交的程序在Online Judge系统下执行时将受到比较严格的限制,包括运行时间限制,内存使用限制和安全限制等.用户程序执行的结果将被Online ...

  7. 杭电OJ:1089----1096(c++)(ACM入门第一步:所有的输入输出格式)

    1089:输入输出练习的A + B(I) 问题描述 您的任务是计算a + b. 太容易了?!当然!我专门为ACM初学者设计了这个问题. 您一定已经发现某些问题与此标题具有相同的名称,是的,所有这些问题 ...

  8. ACM入门

    1.给n个数字,将它们重新排序得到一个最大的数字 例子 4123 124 56 90--------------90561241235123 124 56 90 9------------990561 ...

  9. acm入门编成题

    http://wenku.baidu.com/view/c8f2f64acf84b9d528ea7aee.html

随机推荐

  1. myeclipse连接数据库oracle(添加jdbc.properties)

    第一步:在src下面建一个包com.xsl.conf 第二步:在建好的包下面新建一个jdbc.properties 第三步:在jdbc.properties里写入内容如下: driver = orac ...

  2. Linux Samba服务主配文件smb.conf中文详解

    从网上找到描述比较详细的smb.conf中文解释: 服务名:smb 配置目录:/etc/sabma/ 主配置文件:/etc/sabma/smb.conf #====================== ...

  3. maven package:Max maven Unsupported major.minor version 51.0

    编译maven项目时报错:Max maven Unsupported major.minor version 51.0 major.minor version 51.0 对应的是JDK1.7 majo ...

  4. ios 点击放大图片,保存至手机相册

    直接贴.m文件代码 #import "UIImageView+Scale.h" static CGRect oldframe; @implementation UIImageVie ...

  5. Windows下怎么搭建Python+Selenium的自动化环境

    http://jingyan.baidu.com/article/47a29f244aec6bc014239985.html 注意点:配置了环境变量后需要重启电脑

  6. javaWEB总结(16):jsp错误页面的处理

    前言 网站上线后,jsp页面上有时会出现不友好的错误信息,我们需要展示给用户更加友好的页面.这时候要用到page标签的errorPage和isErrorPage. errorPage 指定当前页面出现 ...

  7. 第七十四节,css边框与背景

    css边框与背景 学习要点: 1.声明边框 2.边框样式 3.圆角边框  本章主要探讨HTML5中CSS边框和背景,通过边框和背景的样式设置,给元素增加更丰富的外观. 声明边框 边框的声明有三个属性设 ...

  8. Sublime Text 2

    常用功能: 安装Package Control:https://sublime.wbond.net/ 多行选择.多行编辑鼠标选中多行,按下 Ctrl+Shift+L (Command+Shift+L) ...

  9. iOS毛玻璃擦除效果

    思路:首先我的思路放两个imageView在Controller里把高清的图片放在下面,带有毛玻璃效果的图片放在上面. //在Controller的view上加一个手势代码如下(温馨提示,开启imae ...

  10. jQuery第九章

    第九章 jQuery Mobile 一.HTML5.0简介 谈到Web设计,我们经常把Web分为三个层: (1)结构层:(2)表现层:(3)行为层. 对应的技术分别是: (1)HTML:(2)CSS: ...