记录洛谷刷题QAQ
Bessie’s cruel second grade teacher has assigned a list of N (1 <= N <= 100) positive integers I (1 <= I <= 10^60) for which Bessie must determine their parity (explained in second grade as ‘Even… or odd?’). Bessie is overwhelmed by the size of the list and by the size of the numbers. After all, she only learned to count recently.
Write a program to read in the N integers and print ‘even’ on a single line for even numbers and likewise ‘odd’ for odd numbers.
POINTS: 25
Bessie那惨无人道的二年级老师搞了一个有 N 个正整数 I 的表叫Bessie去判断“奇偶性”(这个词语意思向二年级的学生解释,就是“这个数是单数,还是双数啊?”)。Bessie被那个表的长度深深地震惊到了,竟然跟栋栋的泛做表格一样多道题!!!毕竟她才刚刚学会数数啊。
写一个程序读入N个整数,如果是双数,那么在单立的一行内输出"even",如果是单数则类似地输出"odd".
* Line 1: A single integer: N
* Lines 2…N+1: Line j+1 contains I_j, the j-th integer to determine even/odd
* Lines 1…N: Line j contains the word ‘even’ or ‘odd’, depending on the parity of I_j
2
1024
5931
even
odd
Two integers: 1024 and 5931
1024 is eminently divisible by 2; 5931 is not
//一个简单的函数
#include<string.h>
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
int main()
{
int n;//n个数
scanf("%d",&n);
//一开始这个方法,发现只有50分,原来是数值太大了,换个方法
// for(int i = 1;i <= n;i++)
// {
// long long num;
// scanf("%d",&num);
// if(num%2 == 0)
// printf("even\n");
// else if(num%2 != 0)
// printf("odd\n");
// }
char num[1000];
for(int i = 1;i <= n;i++)
{
scanf("%s",num);
int len = strlen(num);
if(num[len -1] == '0'||num[len - 1] == '2'||num[len - 1] == '4'||num[len - 1] == '6'||num[len - 1] == '8')
{
printf("even\n");
}
else printf("odd\n");
}
return 0;
}
Farmer John has purchased a new robotic plow in order to relieve him from the drudgery of plowing field after field after field. It achieves this goal but at a slight disadvantage: the robotic plow can only plow in a perfect rectangle with sides of integer length.
Because FJ’s field has trees and other obstacles, FJ sets up the plow to plow many different rectangles, which might end up overlapping. He’s curious as to just how many squares in his field are actually plowed after he programs the plow with various plow instructions, each of which describes a rectangle by giving its lower left and upper right x,y coordinates.
As usual, the field is partitioned into squares whose sides are parallel to the x and y axes. The field is X squares wide and Y squares high (1 <= X <= 240; 1 <= Y <= 240). Each of the I (1 <= I <= 200) plow instructions comprises four integers: Xll, Yll, Xur, and Yur (1 <= Xll <= Xur; Xll <= Xur <= X; 1 <= Yll <= Yur; Yll <= Yur <= Y) which are the lower left and upper right coordinates of the rectangle to be plowed. The plow will plow all the field’s squares in the range (Xll…Xur, Yll…Yur) which might be one more row and column than would initially be assumed (depending on how you go about your assumptions, of course).
Consider a field that is 6 squares wide and 4 squares high. As FJ issues a pair of plowing instructions (shown), the field gets plowed as shown by ‘*’ and ‘#’ (normally plowed field all looks the same, but ‘#’ shows which were most recently plowed):
...... **.... #####.
...... (1,1)(2,4) **.... (1,3)(5,4) #####.
...... **.... **....
...... **.... **....
A total of 14 squares are plowed.
POINTS: 25
Farmer John为了让自己从无穷无尽的犁田工作中解放出来,于是买了个新机器人帮助他犁田。这个机器人可以完成犁田的任务,可惜有一个小小的缺点:这个犁田机器人一次只能犁一个边的长度是整数的长方形的田地。
因为FJ的田地有树和其它障碍物,所以FJ设定机器人去犁很多不同的长方形。这些长方形允许重叠。他给机器人下了P个指令,每个指令包含一个要犁长方形的地。这片田地由长方形的左下角和右上角坐标决定。他很好奇最后到底有多少个方格的地被犁过了。
一般来说,田地被分割为很多小方格。这些方格的边和x轴或y轴平行。田地的宽度为X个方格,高度为Y个方格 (1 <= X <= 240; 1 <= Y <= 240). FJ执行了I (1 <= I <= 200)个指令,每个指令包含4个整数:Xll, Yll, Xur, Yur (1 <= Xll <= Xur; Xll <= Xur <=X; 1 <= Yll <= Yur; Yll <= Yur <= Y), 分别是要犁的长方形的左下角坐标和右上角坐标。机器人会犁所有的横坐标在Xll…Xur并且纵坐标在Yll…Yur范围内的所有方格的地。可能这个长方形会比你想象的多一行一列(就是说从第Xll列到第Xur列一共有Xur - Xll + 1列而不是Xur - Xll列)。
考虑一个6方格宽4方格高的田地。FJ进行了2个操作(如下),田地就被犁成"*“和”#“了。虽然一般被犁过的地看起来都是一样的。但是标成”#"可以更清晰地看出最近一次被犁的长方形。
一共14个方格的地被犁过了。
* Line 1: Three space-separated integers: X, Y, and I
* Lines 2…I+1: Line i+1 contains plowing instruction i which is described by four integers: Xll, Yll, Xur, and Yur
* Line 1: A single integer that is the total number of squares plowed
6 4 2
1 1 2 4
1 3 5 4
14
As in the task’s example.
//粗糙的代码,不够优雅哈哈哈
#include<string.h>
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
int main()
{
int x,y, n;
scanf("%d%d%d",&x,&y,&n);//田地的长宽,还有执行的次数
int num[x+1][y+1];
int x1,y1,x2,y2;
for(int i = 1;i <= x;i++)
{
for(int j = 1;j <= y;j++)
{
num[i][j] = 0;
}
}
int sum = 0;
for(int i = 1;i <= n;i++)//执行了n次
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
for(int j = x1;j <= x2;j++)
{
for(int t = y1;t <= y2;t++)
{
if(num[j][t] == 0)
{
num[j][t] = 1;
sum++;
}
}
}
}
printf("%d\n",sum);
return 0;
}
(原创)
有一天 pb和zs玩游戏 你需要帮zs求出每局的胜败情况
游戏规则是这样的: 每次一个人可以对给出的数进行分割,将其割成两个非零自然数,之后由另一个人选择留下两个数中的其中一个;之后由另一个人进行分割这个剩下的数,重复步骤……
当一个人无法对数进行分割的时候游戏结束,另一个人获胜
现在要你求出N次游戏的胜败
每局由pb先进行分割,如果pb赢输出"pb wins" 如果zs赢输出"zs wins"
注:双方都是绝顶聪明的
第一行一个数N,表示数据组数
之后N行,每行一个数M,表示每局初始的数
共N行,每行一串字符 表示游戏结果
5
1
3
7
20
5
zs wins
zs wins
zs wins
pb wins
zs wins
1<N<50
1<=m<=1000000000
#include<string.h>
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
int main()
{
int n;//数据的组数
scanf("%d",&n);
int num;
for(int i = 1;i <= n;i++)
{
scanf("%d",&num);
//其实你会发现,当给出的数字为奇数时,zs会赢
//同理,为偶数时,pd会赢,那么这道题就很简单了
if(num %2 == 0)
printf("pb wins\n");
else if(num %2 != 0)
printf("zs wins\n");
}
return 0;
}
有 n ( n ≤ 2 × 1 0 6 ) n(n \le 2 \times 10^6) n(n≤2×106) 名同学陆陆续续进入教室。我们知道每名同学的学号(在 1 1 1 到 1 0 9 10^9 109 之间),按进教室的顺序给出。上课了,老师想知道第 i i i 个进入教室的同学的学号是什么(最先进入教室的同学 i = 1 i=1 i=1),询问次数不超过 1 0 5 10^5 105 次。
第一行 2 2 2 个整数 n n n 和 m m m,表示学生个数和询问次数。
第二行 n n n 个整数,表示按顺序进入教室的学号。
第三行 m m m 个整数,表示询问第几个进入教室的同学。
输出 m m m 个整数表示答案,用换行隔开。
10 3
1 9 2 60 8 17 11 4 5 14
1 5 9
1
8
5
//数据比较弱,这样也过了
#include<string.h>
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
int main()
{
int n, m;//n是学生个数,m是询问次数
scanf("%d%d",&n,&m);
int num[n+1];
for(int i = 1;i <= n;i++)
{
scanf("%d",&num[i]);
}
int pot;
for(int i = 1;i <= m;i++)
{
scanf("%d",&pot);
printf("%d\n",num[pot]);
}
return 0;
}
以下为不影响题意的简化版题目。
一个 n × n n\times n n×n 的网格图(标号由 1 1 1 开始)上有 m m m 个探测器,每个探测器有个探测半径 r r r ,问这 n × n n\times n n×n 个点中有多少个点能被探测到。
第一行 3 3 3 个整数 n , m , r n,m,r n,m,r ;
接下来 m m m 行,每行两个整数 x , y x,y x,y表示第 i i i 个探测器的坐标。
能被探测到的点的个数。
5 2 1
3 3
4 2
8
1 ≤ n , m ≤ 100 1\le n,m\le 100 1≤n,m≤100
//一个不够优雅的解答,这很阿尼亚
#include<string.h>
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
int main()
{
int n, m, r;//网格边长,探测仪个数,探测半径
scanf("%d%d%d",&n,&m,&r);
int num[n+1][n+1];
for(int i = 1;i <= n;i++)
{
for(int j = 1;j <= n;j++)
{
num[i][j] = 0;
}
}
int sum = 0;
for(int t = 1;t <= m;t++)
{
int x,y;
scanf("%d%d",&x,&y);
num[x][y] = 1;
double len;
for(int i = 1;i <= n;i++)
{
for(int j = 1;j <= n;j++)
{
len = sqrt((x - i)*(x - i) + (y - j)*(y - j));
if(len <= r)
{
num[i][j] = 1;
}
}
}
}
for(int i = 1;i <= n;i++)
{
for(int j = 1;j <= n;j++)
{
if(num[i][j] == 1)
sum++;
}
}
printf("%d\n",sum);
return 0;
}