PTA B1028 人口普查

判断是否在合法区间,再更新最年长和最年轻的人。

读入新日期来更新时,有可能同时更新最老和最年轻,不能用if ,else 

#include<cstdio>
struct person{
  char name[10];
  int yy,mm,dd;
}oldest,youngest,left,right,temp;

bool LessEqu(person a,person b){
  if(a.yy!=b.yy) return a.yy<=b.yy;
  else if(a.mm!=b.mm) return a.mm<=b.mm;
  else return a.dd<=b.dd;
}
bool MoreEqu(person a,person b){
  if(a.yy!=b.yy) return a.yy>=b.yy;
  else if(a.mm!=b.mm) return a.mm>=b.mm;
  else return a.dd>=b.dd;
}
void init(){
  youngest.yy=left.yy=1814;
  oldest.yy=right.yy=2014;
  youngest.mm=oldest.mm=left.mm=right.mm=9;
  youngest.dd=oldest.dd=left.dd=right.dd=6;
}
int main(){
  init();
  int n,num=0;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%s %d/%d/%d",temp.name,&temp.yy,&temp.mm,&temp.dd);
    if(MoreEqu(temp,left)&&LessEqu(temp,right)){
      num++;
      if(LessEqu(temp,oldest))oldest=temp;
      if(MoreEqu(temp,youngest))youngest=temp;
    }
  }
  if(num==0)printf("0\n");
  else printf("%d %s %s\n",num,oldest.name,youngest.name);
  return 0;
}

 

### A-B PTA Algorithm Implementation and Concept The term **A-B PTA (Algorithm-Based Partition Tolerance Architecture)** is often associated with distributed systems, particularly in the context of sharding databases like Sharding-JDBC[^1]. This architecture focuses on ensuring consistency, availability, and partition tolerance within a system while managing data distribution across multiple nodes. #### Key Concepts Related to A-B PTA 1. **Partitioning Strategy**: In Sharding-JDBC, load balancing algorithms such as `round_robin` or `random` are used to distribute queries evenly among database shards. These strategies align closely with the principles of A-B PTA by optimizing resource allocation during partitions. 2. **Load Balancing Algorithms**: The choice between `round_robin` and `random` depends on specific use cases. For example: - `Round Robin`: Ensures an even distribution over time but may introduce latency due to sequential processing. - `Random`: Provides faster initial responses at the cost of potential unevenness in query distribution. 3. **Dependency Management Issues**: Similar challenges arise when dealing with Maven dependencies for libraries like Pentaho AggDesigner (`org.pentaho:pentaho-aggdesigner-algorithm:jar:5.1.5-jhyde`). If unresolved errors occur, it indicates missing artifacts from repositories[^2], which could stem from network restrictions or misconfigured settings[^4][^5]. 4. **Standard Library Functions**: While unrelated directly to A-B PTA, understanding standard library functions provided by `<algorithm>` in C++ can enhance performance tuning[^3]: ```cpp #include <vector> #include <algorithm> std::vector<int> vec = {3, 1, 4, 1, 5}; int maxValue = *std::max_element(vec.begin(), vec.end()); // Finds maximum value using max() ``` Such utilities help optimize operations required in implementing advanced architectures including those based on A-B PTA concepts. #### Example Code Illustrating Load Balance Logic Below demonstrates how one might implement basic logic resembling aspects of A-B PTA through custom load balancers: ```java import java.util.ArrayList; import java.util.List; public class LoadBalancer { private List<String> servers = new ArrayList<>(); public void addServer(String serverName){ this.servers.add(serverName); } public String getNextServerByRoundRobin(){ static int index=0; if(servers.isEmpty()) throw new IllegalStateException("No available servers"); String selectedServer=servers.get(index % servers.size()); index++; return selectedServer; } } ``` This snippet showcases rudimentary handling akin to what would be necessary under certain conditions dictated by A-B PTA requirements.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值