HIT Winter Day ACM入门
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入门的更多相关文章
- 大牛对ACM入门菜鸟的一些话
首先就是我为什么要写这么一篇日志.原因很简单,就是因为前几天有个想起步做ACM人很诚恳的问我该如何入门.其实就现在而言,我并不是很想和人再去讨论这样的话题,特别是当我发现我有很多的东西要学的时候,我实 ...
- ACM 入门计划
acm 本文由swellspirit贡献 ACM • I can accept failure. but I can't accept not trying. Life is often compar ...
- ACM入门步骤(一)
一般的入门顺序: 0. C语言的基本语法(或者直接开C++也行,当一个java选手可能会更受欢迎,并且以后工作好找,但是难度有点大),[参考书籍:刘汝佳的<算法竞赛入门经典>,C++入门可 ...
- ACM入门指南
本文已经转移到了:http://harryguo.me/2015/11/03/ACM-%E5%85%A5%E9%97%A8%E6%8C%87%E5%8D%97/ 什么是ACM? 想必打开这篇博客的人已 ...
- acm入门 杭电1001题 有关溢出的考虑
最近在尝试做acm试题,刚刚是1001题就把我困住了,这是题目: Problem Description In this problem, your task is to calculate SUM( ...
- ACM入门之OJ~
所谓OJ,顾名思义Online Judge,一个用户提交的程序在Online Judge系统下执行时将受到比较严格的限制,包括运行时间限制,内存使用限制和安全限制等.用户程序执行的结果将被Online ...
- 杭电OJ:1089----1096(c++)(ACM入门第一步:所有的输入输出格式)
1089:输入输出练习的A + B(I) 问题描述 您的任务是计算a + b. 太容易了?!当然!我专门为ACM初学者设计了这个问题. 您一定已经发现某些问题与此标题具有相同的名称,是的,所有这些问题 ...
- ACM入门
1.给n个数字,将它们重新排序得到一个最大的数字 例子 4123 124 56 90--------------90561241235123 124 56 90 9------------990561 ...
- acm入门编成题
http://wenku.baidu.com/view/c8f2f64acf84b9d528ea7aee.html
随机推荐
- C#拾遗(一、基本类型)
1. C#是一种块结构语言,用花括号{}分块,但是用#region和#endregion来定义可以展开和折叠的代码区域 #region 这是引用区 using System; ...... #endr ...
- sqlite增删改查
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android=&q ...
- photoshop切图
1.首先需要用photoshop把psd源文件打开,看看源文件的整体布局.源文件是分层的,方便切图的层次. 2.切图的工具叫做"切片",在左侧面板可以看到.右击可以看到" ...
- 101个Linq例子(40-60)
GroupBy - Simple 2 public void Linq41() { string[] words = { "blueberry", "chimpanzee ...
- Python学习之旅--第二周--元组、字符串、运算、字典
一.元组 另一种有序列表叫元组:tuple.tuple和list非常类似,但是tuple一旦初始化就不能修改,比如同样是列出同学的名字: # Author:Tim Gu tuple = (" ...
- centos解压bz2文件出错
出现的问题: 用tar 解压 tar.bz2文件出错 debian:/usr/src# tar jxf linux-2.6.26.tar.bz2tar: bzip2: Cannot exec: No ...
- python 基础学习3-函数
1. 函数参数-默认参数 python函数也可以跟C语言一样,在函数的形参中设定默认值. >>> def test(flag, port = 8080) ... print port ...
- EventBus消息机制在Eclipse环境下的使用
1.在onStart()方法中注册 @Override public void onStart() { super.onStart(); // 注册 EventBus // 判断 Eventbus 是 ...
- 《JavaScript高级程序设计》读书笔记 ---Function 类型
说起来ECMAScript 中什么最有意思,我想那莫过于函数了——而有意思的根源,则在于函数实际上是对象.每个函数都是Function 类型的实例,而且都与其他引用类型一样具有属性和方法.由于函数是对 ...
- Maze
Maze 题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5094 BFS+状态压缩 把身上携带钥匙的状态压缩成一个2^10的整数.这道题难在 ...