文章目录
- [A - Restoring Three Numbers](https://vjudge.net/contest/364767#problem/A)
- [B - Make Them Equal ](https://vjudge.net/contest/364767#problem/B)
- [C - Gourmet Cat ](https://vjudge.net/contest/364767#problem/C)
- [D - Romaji ](https://vjudge.net/contest/364767#problem/D)
- [E - Turn the Rectangles](https://vjudge.net/contest/364767#problem/E)
A - Restoring Three Numbers
solution
找出最大的值,然后用其余的值去剪输出就好了
#include <stdio.h>
#include <algrithm>
int main(){
int a[5];
while(~scanf("%d %d %d %d",&a[0],&a[1],&a[2],&a[3])){
sort(a,a+4);
printf("%d %d %d\n",a[3]-a[1],a[3]-a[0],a[3]-a[2]);
}
return 0;
}
B - Make Them Equal
solution
首先提出不同的数,若是有3个以上的不同数,不管怎么都不会平均输出-1。当只有两个不同的数时,一种是差值,一种是相减的平均值。当有三个数时,最大的值与最小的值相加除二等于中间值就输出最大的值与最小的值相减除二。否则输出-1。
#include <stdio.h>
int main(){
int n,a[101],num,min,max;
while(~scanf("%d",&n)){
memset(a,-1, sizeof(a));
max = 0;min = 100;int i;
for(i = 0;i < n;i++){
scanf("%d",&num);
a[num] = num;
if(min > num)
min = num;
if(max < num)
max = num;
}
int j;
for(i = min,j = 0;i <= max;i++){
if(a[i] != -1){
a[j+1] = a[i];
if(j > 3){
printf("\n-1\n");
break;
}
j++;
}
}
if(j == 3){
if((a[1] + a[3])/2.0 == a[2])
printf("%d\n",(a[3] - a[1])/2);
else
printf("-1\n");
}
if(j == 2){
if((a[2]-a[1])%2 == 0)
printf("%d\n",(a[2]-a[1])/2);
else
printf("%d\n",a[2]-a[1]);
}
if(j == 1){
printf("0\n");
}
}
return 0;
}
C - Gourmet Cat
solution
求出三个食物能够供给整周所需要的量,将能够提供的最少周数作为基础周数,然后遍历一周,将能够供给的最多天数求出来加上基础周数*7就是总天数
#include <stdio.h>
#include <algorithm>
using namespace std;
int main(){
int a,b,c,f;
int day[] = {0,1,2,0,2,1,0};
while(~scanf("%d %d %d",&a,&b,&c)){
f = min(a/3,min(b/2,c/2));
int count,Max = 0;
for(int i = 0;i < 7;i++){
count = 0;
int str[] = {a - f * 3,b - f * 2,c - f * 2} ;
for(int j = 0;j < 7;j++){
Max = max(Max,count);
count++;
if(!str[day[(j+i)%7]]--){
break;
}
}
}
printf("%d\n",Max+f*7);
}
}
D - Romaji
solution
#include <stdio.h>
#include <string.h>
int main(){
char str[102];
while(gets(str)){
int flag = 1;
for(int i = 0;i < strlen(str);i++){
if(str[i] != 'a' && str[i] != 'e' && str[i] != 'i' && str[i] != 'o' && str[i] != 'u' && str[i] != 'n'){
if(str[i+1] != 'a' && str[i+1] != 'e' && str[i+1] != 'i' && str[i+1] != 'o' && str[i+1] != 'u'){
flag = 0;break;
}
}
}
if(flag)
printf("YES\n");
else{
printf("NO\n");
}
}
}
E - Turn the Rectangles
solution
取每一个矩形最长的一边储存,满足最小的一边不超过前一个矩形的边的前提下,如果最大边小于前一个矩形就取最大边,否则取最小边。如果不满足情况就输出“NO”
#include <stdio.h>
#include <string.h>
int max(int a,int b){
if(a > b)
return a;
else
return b;
}
int min(int a,int b){
if(a < b)
return a;
else
return b;
}
int main(){
int n,num1,num2;
int s[100001];
while(~scanf("%d",&n)){
int flag = 1;
for(int i = 0;i < n;i++){
scanf("%d %d",&num1,&num2);
if(i == 0)
s[0] = max(num1,num2);
else
if(min(num1,num2) > s[i-1]){
flag = 0;
}
else if(max(num1,num2) > s[i-1]){
s[i] = min(num1,num2);
}
else{
s[i] = max(num1,num2);
}
}
if(flag) {
printf("YES\n");
}
else
printf("NO\n");
}
}