【day13】
题目:13号又是星期五是一个不寻常的日子吗? 13号在星期五比在其他日少吗?为了回答这个问题,写一个程序来计算在n年里13 日落在星期一,星期二......星期日的次数.这个测试从1900年1月1日到 1900+n-1年12月31日.n是一个非负数且不大于400.
这里有一些你要知道的: 1900年1月1日是星期一. 4,6,11和9月有30天.其他月份除了2月都有31天.闰年2月有29天,平年2月有28天.
七个在一行且相分开的整数,它们代表13日是星期六,星期日,星期一.....星期五的次数.
个人总结:
- time记录13号出现在周一到周日的次数
- dieta从下标1开始记录i月到i+1月13号周几的变化,例如1900年1月13号是周六,2月13号是(6+dieta[1])%7=2,周二
- runy判断是否是闰年,若是闰年,且当前是2月,week要再加一
#include
using namespace std;
int runy(int n) {
if (n % 400 == 0 || (n % 100 != 0 && n % 4 == 0)) {
return 1;
}
return 0;
}
int main() {
int time[8] = { 0,0,0,0,0,0,0,0 };
int dieta[13] = { 0,3,0,3,2,3,2,3,3,2,3,2,3 };
int n;
cin >> n;
int week = 6;
if (n < 1 || n > 400)return 0;
for (int i = 1900; i < 1900 + n; i++) {
for (int j = 1; j < 13; j++) {
time[week]++;
week += dieta[j];
if (j == 2 && runy(i)) {
week++;
}
if (week > 7) {
week %= 7;
}
}
}
cout << time[6] << " " << time[7] << " " << time[1] << " " << time[2] << " " << time[3] << " " << time[4] << " " << time[5];
return 0;
}
题目:明明是一家地铁建设公司的职员,他负责地铁线路的规划和设计。一次,明明要在一条长L的马路上建造若干个地铁车站。
这条马路有一个特点,马路上种了一排树,每两棵相邻的树之间的间隔都是一米。
如果把马路看成一个数轴,马路的一端在数轴0的位置,马路的另一端在L的位置,那么这些树都种在数轴的整数点上,即0,1,2,…,L上都种有一棵树。
由于要设计建造地铁站的缘故,所以需要把一些树移走,明明为了移树的方便,把地铁站的区域也建在了数轴上两个整数点之间,由于有多条地铁线路,地铁车站的区域可能会有部分的重合(重合的区域明明将来会设计成一个大型的车站,移树的时候不必考虑地铁站重合区域的问题)。
现在明明想请你帮一个忙,他把车站区域的位置告诉你,即告诉你数轴上的两个整数点,在这两个整数点之间是车站的区域,请你写一个程序,计算出把所有车站区域两点之间的树移走以后,这条马路上还剩多少棵树。
例如:马路长为10,要建造2个地铁车站,车站的区域分别是2到5和3到6,原先的马路上一共有11棵树,在2到5的位置上建车站后,需要移走4棵树,在3到6的位置上建车站后,也需要移走4棵树,但是3到6这个区域和2到5这个区域有部分重合,所以只需移走1棵树即可,这样总共移走的树是5棵,剩下的树就是6棵。
明明的问题可以归结为:给你一条马路的长度和若干个车站的位置,请你用程序计算出把树移走后,马路上还剩多少棵树。
个人总结:
- 设置数组a记录0~L上树情况,为0就是有树
- 移走树就将当前位置的值置为1
#include
using namespace std;
int a[10001];
int main() {
int L, M;
while (cin >> L >> M) {
for (int i = 0; i < 10001; i++) {
a[i] = 0;
}
while (M > 0) {
int s, d;
cin >> s >> d;
int cnt = 0;
for (int i = s; i <= d; i++) {
if (a[i] == 0) {
a[i] = 1;
}
}
M--;
if(M==0){
for (int i = 0; i <= L; i++) {
if (a[i] == 0) {
cnt++;
}
}
cout << cnt << endl;
}
}
}
return 0;
}
题目:有一次,明明的公司举行忘年会。忘年会的高潮部分是最后的抽大奖环节。公司为了增加活动的气氛,并没有按传统的抽奖方式来抽,而是进行了一个游戏:逐步逐步地淘汰人,而最后剩下的人,将会得到大奖。
- 这个游戏的方式如下:首先公司的全部职员围成一个圈,然后确定一个淘汰数X,接着就从其中的一个人开始,从1数数,当数到X时,那个人就被淘汰出局,接着下一个人再从1开始数数,一直这样重复下去,直到剩下最后一个人,那个人就是最后的大奖得主。
例如,公司有5个人,淘汰数定为2,则一开始五个人排成一圈,依次编号为:1、2、3、4、5; 首先从编号1的人开始数数,数到2后,编号2淘汰,这样只剩下4个人:1、3、4、5; 接着从编号3的人开始数,数到2后,编号4淘汰,这样只剩下3个人:1,3、5; 接着从编号5的人开始数,数到2后,编号1淘汰,这样只剩下2个人:3、5; 最后从编号为3的人开始数,数到2后,编号5淘汰,最后编号为3的那个人就获得了最终的大奖。 (注:以上的淘汰顺序为2 4 1 5 3。)
由于明明的运气十分地差,最后第二个被淘汰,与大奖失之交臂,十分郁闷。他想知道自己被淘汰的全过程,于是他想请你帮个忙,帮他写一个程序,明明把他公司的人数告诉你,并且把那个淘汰数也告诉你,你的程序能够根据这两个数计算出淘汰人的具体顺序,即把淘汰人的编号按顺序输出。
明明的问题可以归结为:给你一个公司的人数N和一个淘汰数X,你的程序模拟上面描述的淘汰方式,输出淘汰人的编号顺序。
个人总结:
- 设置数组a,记录对每个值的淘汰情况,防止重复淘汰
- 用step计算淘汰位置,a[out]等于0的时候step--,不等于step不变
- 最后out一定要+1,按照下一个的位置进行计算
#include
using namespace std;
int main() {
int n, x;
while (cin >> n >> x) {
int out = 1;
bool f = false;
int* a = new int[n + 1]();
for (int i = 1; i <= n; i++) {
int step = x;
while (step > 0) {
if (a[out] == 0) {
step--;
}
if (step > 0) {
out++;
if (out > n) {
out = 1;
}
}
}
if (f)cout << " ";
else f = true;
cout << out;
a[out] = 1;
out++;
if (out > n) {
out = 1;
}
}
free(a);
cout << endl;
}
}
Translation:
More recent examples of Turing test "successes"include Internet viruses that carry on "intelligent"dialogs with a human victim in order to trick the humaninto dropping his or her malware guard. Moreover,phenomena similar to Turing tests occur in the contextof computer games such as chess-playing programs.Although these programs select moves merely byapplying brute-force[插图] techniques, humanscompeting against the computer often experience thesensation that the machine possesses creativity andeven a personality. Similar sensations occur in roboticswhere machines have been built with physicalattributes that project intelligent characteristics.Examples include toy robot dogs that project adorablepersonalities merely by tilting their heads or lifting their ears in response to a sound.
Virtual reality (VR[插图]) is becoming increasingly popular,as computer graphics have progressed to a point where the images are often indistinguishable from the realworld. However, the computer-generated imagespresented in games, movies, and other media aredetached from our physical surroundings. This is botha virtue—everything becomes possible—and alimitation. The limitation comes from the main interestwe have in our daily life, which is not directed towardsome virtual world, but rather toward the real worldsurrounding us.
In many ways, enhancing mobile computing so that theassociation with the real world happens automatically seems an attractive proposition. Augmented reality(AR[插图]) holds the promise of creating direct, automatic,and actionable links between the physical world andelectronic information. It provides a simple andimmediate user interface to an electronically enhancedphysical world. AR can overlay computer-generatedinformation on views of the real world, amplifyinghuman perception and cognition in remarkable newways.
- malware 恶意软件
- brute 野兽 残忍的人 兽性
- brute-force 蛮力
- tilt 倾斜
- trial-and-error 反复试验的
- checkers 西洋跳棋
- adorable 可爱的 值得崇拜的
- proposition 提议
- hold the promise of doing 有望做
- remarkable 值得注意的 引人注目的 非凡的 卓越的
最近的关于图灵测试“成功”的例子包括互联网病毒,与人类受害者进行“智能”对话以欺骗人们放弃对恶意软件的防护。而且,相似于图灵测试的现象发生在计算机游戏的背景下,例如下棋程序。尽管这些程序仅仅通过运用暴力破解技术来选择走法,但与计算机对弈的人类常会产生一种感觉:这台机器拥有创造力,甚至具备个性。相似的感觉也出现在机器人上,由物理特性构成的机器投射出了智能特性。例子有,机器狗仅仅通过倾斜头部或抬起耳朵来响应声音以投射可爱的个性。
VR变得越来越受欢迎,随着机器图像进步到图像常无法与真实世界进行区分。然而,计算机在游戏,电影以及其他媒体中产生的图像脱离我们物理环境。这不仅是一种美德——任何事变为可能——也是一种限制。限制来自于我们在日常生活中的主要兴趣,这不指向虚拟世界,而是指向我们周围的现实世界。
在许多方面,增强移动计算,使与知识世界的联系自动发生,似乎是一个有吸引力的命题。AR有望在物理世界与电子信息之间创造直接、自动且可执行的链接。它给电子增强的物理世界提供了一个简单直接的用户界面。AR可以将计算机生成的信息叠加在真实世界观上,放大了人类对卓越新方式的感知和认识。









