F - Tickets

添加链接描述

Last n days Monocarp used public transport to get to the university. He received a ticket with number ti during the i-th day.

Tickets’ numbers are six digit non-negative integers with possible leading zeroes. For example, 123456, 000000, 099999, 999999 are correct ticket numbers, but 1234567, 12345, 9 are not. Every day tickets are numbered from zero. The first passenger gets ticket number 000000, the second one — ticket number 000001, the third one — number 000002 and so on every day. Assume that each day the number of passengers doesn’t exceed 106.

Unluckiness of the ticket is equal to absolute difference between the sum of the first three digits and the sum of the last three. For example, unluckiness of the ticket number 345123 is equal to |(3+4+5)−(1+2+3)|=6, or unluckiness of the ticket number 238526 is equal to |(2+3+8)−(5+2+6)|=0.

One passenger is luckier than other if unluckiness of first passenger’s ticket is strictly less than unluckiness of the second one’s ticket.

For each of n days for given Monocarp’s ticket’s number ti calculate the number of passengers who received their tickets before him during this day and are luckier than Monocarp.

Examine examples for the further understanding of the statement.

Input
The first line contains one integer n (1≤n≤2⋅105) — the number of days during which Monocarp used public transport.

Each of the next n lines contains one six digit integer ti (0≤ti<106, ti can have leading zeroes) — the ticket Monocarp received during the corresponding day.

Output
Print n lines: one integer per line — the number of passengers who received their tickets before Monocarp during the corresponding day and are luckier than Monocarp.

Example
Input
5
001000
000000
999000
453234
654331
Output
1
0
998999
121496
470362
Note
During the first day the only one passenger who got ticket before Monocarp was luckier. This passenger got ticket number 000000.

During the second day Monocarp was the first one, so there was nobody before him.

During the third day all passengers except one who got tickets before Monocarp were more luckier than him. The one whose unluckiness was equal to Monocarp’s unluckiness got ticket number 000999.

对数据提前进行预处理
/**/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int a[1000010];
int f[100];
int main()
{
    int i,j,k,x,y,n,m;
    memset(f,0,sizeof(f));
    for(i=0; i<1000000; i++)
    {
        a[i]=0;
        x=0;
        y=0;
        x+=i/100000;
        x+=(i/10000)%10;
        x+=(i/1000)%10;
        y+=(i/100)%10;
        y+=(i/10)%10;
        y+=i%10;
        k=abs(x-y);
        f[k]++;
        for(j=0; j<k; j++)
            a[i]+=f[j];
    }
    scanf("%d",&n);
    while(n--)
    {
        scanf("%d",&m);
        printf("%d\n",a[m]);
    }
    return 0;
}



TL
/**/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int a[1000010];
int f[100];
int main()
{
    int i,j,k,x,y,n,m;
    memset(f,0,sizeof(f));
    for(i=0; i<1000000; i++)
    {
        a[i]=0;
        x=0;
        y=0;
        x+=i%10;
        i/=10;
        x+=i%10;
        i/=10;
        x+=i%10;
        i/=10;
        y+=i%10;
        i/=10;
        y+=i%10;
        i/=10;
        y+=i%10;
        k=abs(x-y);
        f[k]++;
        for(j=0; j<k; j++)
            a[i]+=f[k];
    }
    scanf("%d",&n);
    while(n--)
    {
        scanf("%d",&m);
        printf("%d\n",a[m]);
    }
    return 0;
}
画出以下代码逻辑流程图#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <windows.h> // 客户信息结构体 typedef struct Customer { char name[50]; char id[20]; int tickets; struct Customer *next; } Customer; // 航线信息结构体 typedef struct Flight { char number[20]; // 航班号 char from[50]; // 出发地 char to[50]; // 目的地 char date[20]; // 飞行日期 char dep_time[10]; // 起飞时间 char arr_time[10]; // 到达时间 int capacity; // 乘员定额 int remaining; // 余票量 Customer *customers;// 客户链表 struct Flight *next; } Flight; Flight *flights = NULL; // 全局航线链表 // 函数声明 void load_data(); void save_data(); void show_menu(); void show_all_flights(); void search_by_destination(); void search_by_flight_number(); void book_ticket(); void return_ticket(); void show_customers(); void clear_input_buffer(); Flight* find_flight(const char *number); Customer* find_customer(Flight *f, const char *name); int main() { load_data(); int choice; do { system("cls||clear");//清屏 show_menu(); printf("请输入选项:"); scanf("%d", &choice); clear_input_buffer(); // 清除输入缓冲区 switch(choice) { case 1: show_all_flights(); break; case 2: search_by_destination(); break; case 3: book_ticket(); break; case 4: return_ticket(); break; case 5: show_customers(); break; case 0: save_data(); break; default: printf("无效选项!\n"); Sleep(3000);break; } } while(choice != 0); return 0; } // 加载航班数据 void load_data() {5 FILE *fp = fopen("flights.txt", "r"); if(!fp) return; Flight *current = NULL; char line[256]; while(fgets(line, sizeof(line), fp)) { Flight *f = (Flight*)malloc(sizeof(Flight)); memset(f, 0, sizeof(Flight)); // 解析航班数据 sscanf(line, "%s %s %s %s %s %s %d %d", f->number, f->from, f->to, f->date, f->dep_time, f->arr_time, &f->capacity, &f->remaining); f->customers = NULL; f->next = NULL; // 添加到链表 if(!flights) flights = f; else current->next = f; current = f; } fclose(fp); } // 保存数据到文件 void save_data() { FILE *fp = fopen("flights.txt", "w"); Flight *f = flights; while(f) { fprintf(fp, "%s %s %s %s %s %s %d %d\n", f->number, f->from
03-17
内容概要:本文档详细介绍了基于事件触发扩展状态观测器(ESO)的分布式非线性车辆队列控制系统的实现。该系统由N+1辆车组成(1个领头车和N个跟随车),每辆车具有非线性动力学模型,考虑了空气阻力、滚动阻力等非线性因素及参数不确定性和外部扰动。通过事件触发ESO估计总扰动,基于动态面控制方法设计分布式控制律,并引入事件触发机制以减少通信和计算负担。系统还包含仿真主循环、结果可视化等功能模块。该实现严格遵循论文所述方法,验证了观测误差有界性、间距误差收敛性等核心结论。 适合人群:具备一定编程基础,对非线性系统控制、事件触发机制、扩展状态观测器等有一定了解的研发人员和研究人员。 使用场景及目标:①研究分布式非线性车辆队列控制系统的理论与实现;②理解事件触发机制如何减少通信和计算负担;③掌握扩展状态观测器在非线性系统中的应用;④学习动态面控制方法的设计与实现。 其他说明:本文档不仅提供了详细的代码实现,还对每个模块进行了深入解析,包括非线性建模优势、ESO核心优势、动态面控制与传统反步法对比、事件触发机制优化等方面。此外,文档还实现了论文中的稳定性分析,通过数值仿真验证了论文的核心结论,确保了系统的稳定性和有效性。建议读者在学习过程中结合代码进行实践,并关注各个模块之间的联系与相互作用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值