Paper Work Cf250A

Paper Work
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day.

Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on.

It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible.

Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal.

Write a program that, given sequence ai, will print the minimum number of folders.

Input

The first line contains integer n (1 ≤ n ≤ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an(|ai| ≤ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai.

Output

Print an integer k — the required minimum number of folders. In the second line print a sequence of integers b1b2, ..., bk, where bj is the number of day reports in the j-th folder.

If there are multiple ways to sort the reports into k days, print any of them.

Sample Input

Input
11
1 2 3 -4 -5 -6 5 -5 -6 -7 6
Output
3
5 3 3 
Input
5
0 -1 100 -1 0
Output
1
5 

题意:给出n个数,分成m堆,每堆最多只能有两个负数,求最小的堆数,并输出每堆的个数。

简单的贪心,但写起来还是把我会搞死。。。。。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;

int a[110],b[110];

int main()
{
    int n,ans;
    while (~scanf("%d",&n))
    {
        ans=0;
        int num=0;
        for (int i=0;i<n;i++)
            scanf("%d",&a[i]);
        for (int i=0;i<n;i++)
        {
            if (a[i]<0&&num<3)
                num++;
            if (num==3)
            {
                b[ans]=i;
                ans++;
                num=1;
            }
        }
//        printf("%d %d\n",ans,num);
        b[ans]=n;
        ans++;
        if (ans==0)
        {
            ans=1;
            b[0]=n;
        }
        printf("%d\n",ans);
        printf("%d",b[0]);
        if (ans>1){
        for (int i=1;i<ans;i++)
            printf(" %d",b[i]-b[i-1]);}
        printf("\n");
    }
    return 0;
}
/*
7
-1 -2 3 4 5 6 -7
8
-1 -1 -1 -1 -1 -1 -1 -1
*/


<think> 我们正在讨论在Windows下使用Perfetto抓取系统级CPU调度和频率事件时,provider_guid的来源问题。 根据用户的问题,他之前已经得到了关于如何配置Perfetto的ETW提供者的信息,其中使用了两个provider_guid: - 调度事件:"{DE7B24EA-73C8-4A09-9853-8CF250BE0F22}" - 频率事件:"{0F67E49F-FE51-4E9F-B490-6F2948CC6027}" 用户现在想知道这些GUID的来源。 在Windows中,ETW(Event Tracing for Windows)提供者通过GUID唯一标识。这些GUID是预定义的,由Microsoft在定义ETW提供者时分配。 我们可以通过以下方式获取这些GUID: 1. **官方文档**:Microsoft文档会列出核心内核提供者的GUID。 例如,调度事件的提供者名为"Microsoft-Windows-Kernel-Scheduler",其GUID在文档中给出。 频率事件的提供者名为"Microsoft-Windows-Kernel-Processor-Power"。 2. **使用Windows SDK中的工具**:我们可以使用`logman`命令查询已注册的ETW提供者,或者使用`tracelog`工具。 例如,在管理员权限的命令提示符中运行: `logman query providers` 这会列出所有已注册的提供者及其GUID。 3. **通过Perfetto文档**:Perfetto官方文档可能也会列出常用的Windows ETW提供者GUID。 4. **通过Windows头文件**:在Windows SDK的头文件中,这些GUID也被定义。 具体到这两个提供者: - **调度事件提供者**:`Microsoft-Windows-Kernel-Scheduler` 其GUID为`{DE7B24EA-73C8-4A09-9853-8CF250BE0F22}`,定义在`Kernel-Scheduler`相关的头文件中。 - **CPU频率事件提供者**:`Microsoft-Windows-Kernel-Processor-Power` 其GUID为`{0F67E49F-FE51-4E9F-B490-6F2948CC6027}`,定义在`Kernel-Processor-Power`相关的头文件中。 我们可以通过在Windows SDK的`Windows.h`或相关头文件中查找,但更直接的方式是使用命令行工具查询。 例如,使用PowerShell命令查询调度提供者的GUID: ```powershell Get-WinEvent -ListProvider * | Where-Object {$_.Name -like "*Kernel-Scheduler*"} | Format-List Name, Id ``` 或者使用命令提示符: ```cmd logman query providers "Microsoft-Windows-Kernel-Scheduler" ``` 注意:有些提供者可能需要在注册表中查找,但上述方法通常有效。 因此,在配置Perfetto时,我们需要使用这些预定义的GUID来指定要捕获的事件提供者。 如果用户需要捕获其他事件,可以按照同样的方式查询相应提供者的GUID。 补充:Perfetto的配置文件中,我们使用`provider_guid`字段来指定这些GUID。 总结:provider_guid来源于Windows操作系统定义的ETW提供者,可以通过官方文档、系统工具或头文件获取。 现在,我们按照用户要求的格式进行回答。 </think> ### Perfetto 在 Windows 下获取 ETW Provider GUID 的方法 在 Windows 系统下使用 Perfetto 抓取 CPU 调度和频率等内核事件时,`provider_guid` 的来源主要有以下三种途径: #### 1. **Microsoft 官方文档** Microsoft 官方文档明确列出了所有内核 ETW 提供者的 GUID。核心来源: - **CPU 调度事件**的 GUID `{DE7B24EA-73C8-4A09-9853-8CF250BE0F22}` 来自: ``` Microsoft-Windows-Kernel-Scheduler ``` - **CPU 频率事件**的 GUID `{0F67E49F-FE51-4E9F-B490-6F2948CC6027}` 来自: ``` Microsoft-Windows-Kernel-Processor-Power ``` 完整列表参考:[Windows Kernel Provider GUIDs](https://learn.microsoft.com/en-us/windows/win32/etw/system-providers) [^1] #### 2. **Windows 内置工具** 通过系统命令行工具获取实时 GUID: ```powershell # 列出所有已注册的 ETW 提供者 logman query providers # 精确查询调度提供者 GUID logman query providers "Microsoft-Windows-Kernel-Scheduler" # 输出示例: # Provider GUID # ------------------------------------------------------------------------------ # Microsoft-Windows-Kernel-Scheduler {DE7B24EA-73C8-4A09-9853-8CF250BE0F22} ``` #### 3. **Windows SDK 头文件** 在开发环境中直接从 SDK 头文件提取: ```c // 调度提供者 GUID (wmicore.mof) [Provider("{DE7B24EA-73C8-4A09-9853-8CF250BE0F22}")] class Microsoft_Windows_Kernel_Scheduler // 频率提供者 GUID (powerprof.h) DEFINE_GUID( /* 0F67E49F-FE51-4E9F-B490-6F2948CC6027 */ 0x0F67E49F, 0xFE51, 0x4E9F, 0xB4, 0x90, 0x6F, 0x29, 0x48, 0xCC, 0x60, 0x27 ); ``` 文件位置:`C:\Program Files (x86)\Windows Kits\10\Include\<version>\um` [^2] #### 其他关键 GUID | **内核事件类型** | **Provider 名称** | **GUID** | |----------------------|------------------------------------------|--------------------------------------------| | 上下文切换 | Microsoft-Windows-Kernel-Dispatch | `{F8C110C8-042D-4FD7-8B81-4A1D0D8EC2F9}` | | 中断处理 | Microsoft-Windows-Kernel-Interrupt | `{C37A9D2A-FD14-4A20-9FE3-0C37FE0E0E08}` | | 电源状态转换 | Microsoft-Windows-Kernel-Power | `{331C3B3A-2005-44C2-AC5E-77220C37D6B4}` | > ⚠️ **注意事项**: > 1. GUID 具有系统版本依赖性,Windows 10 和 Windows 11 部分提供者 GUID 不同 > 2. 第三方驱动需通过 `logman` 或 `tracelog -l` 查询自定义 GUID > 3. Perfetto 配置文件必须使用十六进制 GUID 格式 [^3] --- ### 相关问题 1. 如何验证 Windows ETW Provider 是否正常工作? 2. Perfetto 能否捕获 Windows 硬件中断事件的详细数据? 3. 自定义 Windows 内核驱动如何注册 ETW Provider? 4. Windows 不同版本的内核事件 Provider GUID 差异如何管理? 5. Perfetto 在捕获 ETW 事件时如何避免数据丢失? [^1]: Microsoft Docs, "About Event Tracing", 2023 [^2]: Windows SDK, "ETW Provider Header Files", 2023 [^3]: Perfetto Docs, "Windows ETW Configuration", 2024
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值