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. centos7内核升级

    默认centos7的内核版本是3.10,升级的原因是为了测试openvswitch的vlan技术,默认openvswitch的2.3版本是允许centos7默认内核3.10支持,下面是软件与内核版本对 ...

  2. day23 框架之基础加强

    day23 框架之基础加强 今日任务 aptana(javascript的eclipse插件):http://www.cnblogs.com/terrylin/archive/2012/06/20/2 ...

  3. Python Data Visualization Cookbook 2.2.2

    import csv filename = 'ch02-data.csv' data = [] try: with open(filename) as f://用with语句将数据文件绑定到对象f r ...

  4. 阮一峰:MVC、MVP和MVVM的图示

    阮一峰:MVC.MVP和MVVM的图示:http://www.ruanyifeng.com/blog/2015/02/mvcmvp_mvvm.html

  5. php 基础篇 php 进阶篇

    1:echo 12*3: 2  echo "Welcome" . " to imooc!";字符串连接. 3>foreach($shuzu as $key ...

  6. jQuery复习:第四章

    一.jQuery中的事件 1.加载DOM $(document).ready()和window.onload方法具有类似功能,但是执行时机不同.window.onload方法是在网页中所有的元素都加载 ...

  7. php中 xml json 数组 之间相互转换

    php中 xml json  数组 之间相互转换 1 数组转json $result = array( 'status' =>$status, 'message'=>$message, ' ...

  8. hdu2141AC代码分享

    #include <iostream> #include <algorithm> using namespace std; const int N = 505; /////// ...

  9. BestCoder Round #86 A B C

    这次BC终于不像上次一样惨烈 终于A了三题…… 终测ing…… 发一波题解…… A.Price List A题十分无脑 只要把所有数加起来存到sum里 询问的时候大于sum输出1 否则输出0就行了…… ...

  10. Vultr免费vps注册和使用简易教程

    如果你是站长,寻找托管网站的主机,或者是开发者,需要搭建服务器环境,选购vps是必须的.强烈不推荐国内的vps产品,没有性价比,维护水平又烂,甚至某些国内所谓云主机vps安装后门,监控你的数据.海外v ...