得分:460分,一等500 (我还是太菜了)
总结:主要是第5题太可惜了(才20分)
下次要理清思路,想好具体做法再做
(似乎历年都是5或6题考贪心)
A. 打印方阵
题目描述
下面这样的方阵很有规律,称为蛇形方阵。例如3×3的:
1 2 3
6 5 4
7 8 9
现在给定边长,输出相应的蛇形方阵。
输入格式
一个整数n,表示要输出n×n的蛇形方阵,1≤n≤100。
输出格式
n行,每行n个整数,空格隔开。
样例
样例输入 1
4
样例输出 1
1 2 3 4
8 7 6 5
9 10 11 12
16 15 14 13
直接暴力,没有细节。
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cmath>
using namespace std;
int n;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
if(i%2==1)
{
for(int j=(i-1)*n+1;j<=i*n;j++)
cout<<j<<" ";
cout<<endl;
}
if(i%2==0)
{
for(int j=i*n;j>=(i-1)*n+1;j--)
cout<<j<<" ";
cout<<endl;
}
}
return 0;
}
B. 分数减法
题目描述
这样的分式运算我们都会。请编程计算两个分数相减的结果。
输入格式
第一行,两个整数a和b,表示一个分数abab,1≤a<b≤10000。
第二行,两个整数c和d,表示一个分数cdcd,1≤c<d≤10000。
输入数据保证计算结果为正。
输出格式
两个整数,表示结果。
提示:运算结果分式要约分。
样例
样例输入 1
4 7
1 3
样例输出 1
5 21
注意结果要约分
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cmath>
using namespace std;
int z1,m1,z2,m2,a1,a2,k;
int main()
{
cin>>z1>>m1>>z2>>m2;
for(int i=