import java.util.Scanner;
public class Main {
public static void main(String[] arg) {
Scanner scanner = new Scanner(System.in);
// todo
}
}
NC253181. Envy-freeness
描述
输入描述
The first line contains one integerEach of the followinglines contains three integers
and
输出描述
After each operation, output a single line with:If the current allocation is "envy-free", then output "EF";Otherwise if the current allocation is "envy-free up to any good", then output "EFX";Otherwise if the current allocation is "envy-free up to one good", then output "EF1";Otherwise output "E".
示例1
输入:
5 5 2 0 5 2 1 2 2 0 9 2 1 9 2 1
输出:
EFX EF EFX EF1 E
C++(clang++ 11.0.1) 解法, 执行用时: 433ms, 内存消耗: 3628K, 提交时间: 2023-06-03 20:22:03
#include<bits/stdc++.h>using namespace std;typedef long long LL;LL t,c,e,b,isumj,isumi,jsumi,jsumj,imin = LONG_MAX,jmin = LONG_MAX,imax = 0,jmax = 0;void solve(){scanf("%lld%lld%lld",&c,&e,&b);if(b == 0){isumi += c;isumj += e;jmin = min(jmin,e);jmax = max(jmax,e);}else{jsumi += c;jsumj += e;imin = min(imin,c);imax = max(imax,c);}if(jsumj >= isumj and isumi >= jsumi)printf("EF\n");else if(isumi >= jsumi - imin and jsumj >= isumj - jmin)printf("EFX\n");else if(isumi >= jsumi - imax and jsumj >= isumj - jmax)printf("EF1\n");elseprintf("E\n");}signed main(){cin >> t;while(t--)solve();return 0;}
C(gcc 7.5.0) 解法, 执行用时: 435ms, 内存消耗: 3536K, 提交时间: 2023-06-22 02:32:34
#include<stdio.h>long max(long a, long b) {return a > b ? a : b;}long min(long a, long b) {return a < b ? a : b;}long ii,ij,ji,jj,a,s,z=1e6,x=1e6,m,c,e,b;int main() {scanf("%ld",&m);while(m--){scanf("%ld%ld%ld", &c, &e, &b);if(!b){ii+=c;ij+=e;s=max(s,e);x=min(x,e);}else{ji+=c;jj+=e;a=max(a,c);z=min(z,c);}if(ii>=ji&&jj>=ij)printf("EF\n");else if((ji-z<=ii)&&(ij-x<=jj))printf("EFX\n");else if((ji-a<=ii)&&(ij-s<=jj))printf("EF1\n");else printf("E\n");}return 0;}
C++(g++ 7.5.0) 解法, 执行用时: 464ms, 内存消耗: 3640K, 提交时间: 2023-06-22 02:33:54
#include<iostream>using namespace std;long ii,ij,ji,jj,a,s,z=1e6,x=1e6,m,c,e,b;int main() {cin>>m;while(m--){scanf("%d%d%d",&c,&e,&b);if(!b){ii+=c;ij+=e;s=max(s,e);x=min(x,e);}else{ji+=c;jj+=e;a=max(a,c);z=min(z,c);}if(ii>=ji&&jj>=ij)printf("EF\n");else if((ji-z<=ii)&&(ij-x<=jj))printf("EFX\n");else if((ji-a<=ii)&&(ij-s<=jj))printf("EF1\n");else printf("E\n");}return 0;}