G - Alice, Bob and Chocolate

14 篇文章 0 订阅
4 篇文章 0 订阅
G - Alice, Bob and Chocolate
Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

Alice and Bob like games. And now they are ready to start a new game. They have placed n chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman.

How many bars each of the players will consume?

Input

The first line contains one integer n (1 ≤ n ≤ 105) — the amount of bars on the table. The second line contains a sequence t1, t2, ..., tn(1 ≤ ti ≤ 1000), where ti is the time (in seconds) needed to consume the i-th bar (in the order from left to right).

Output

Print two numbers a and b, where a is the amount of bars consumed by Alice, and b is the amount of bars consumed by Bob.

Sample Input

Input
5
2 9 8 2 7
Output
2 3
#include<iostream>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <vector>
#include <bitset>
#include <cstdio>
#include <string>
#include <numeric>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
#define Exp 1e-8
#define inf 0x7fffffff
#define Read freopen("in.txt","r",stdin)
#define Write freopen("out.txt","w",stdout)
#define maxn 55
#define mod 1000000007

int main()
{
    int n,N;
    int j=1,k=1;
    int a[100050]= {0};
    long long sum1=0,sum2=0;
    cin>>n;
    N=n;
    for(int i=1; i<=n; i++)
        cin>>a[i];
    if(n==1)
    {
        cout<<"1 0"<<endl;
        return 0;
    }
    sum1+=a[j];
    sum2+=a[N+1-k];
    n-=2;
    while(n>0)//模拟吃巧克力,一人一块,注意,还要有绅士风度~~
    {
        if(sum1>sum2)
        {
            k++;
            sum2+=a[N+1-k];
            n--;
        }
        else if(sum1==sum2)
        {
            if(n==1)
            {
                j++;
                n--;
                break;
            }
            j++;
            k++;
            sum1+=a[j];
            sum2+=a[N+1-k];
            n-=2;
        }
        else
        {
            j++;
            sum1+=a[j];
            n--;
        }
    }
    cout<<j<<" "<<k<<endl;
    return 0;
}


抱歉,我不太明白你的问题。你是在询问如何使用DES算法进行通信并将数据存储到Python数据库中吗?如果是,我可以为你提供一些指导。 首先,DES算法是一种对称密钥算法,它需要AliceBob共享一个密钥。为了使用DES算法进行通信,AliceBob需要遵循以下步骤: 1. 首先,AliceBob需要协商一个密钥。可以使用Diffie-Hellman密钥交换算法来协商密钥,或者可以在安全通道上手动交换密钥。 2. 一旦密钥协商完成,AliceBob就可以使用DES算法对消息进行加密和解密。在Python中,可以使用pyDes库来实现DES加密和解密。 3. 如果需要将加密后的数据存储到数据库中,可以使用Python中的sqlite3库来创建和连接数据库,并使用SQL语句将加密后的数据保存到数据库中。 下面是一个示例代码,演示如何使用DES算法进行通信并将数据存储到Python数据库中: ```python import pyDes import sqlite3 # 协商密钥 key = b"mysecret" # 加密消息 message = b"Hello Bob" des = pyDes.des(key, pyDes.ECB, pad=None, padmode=pyDes.PAD_PKCS5) encrypted_message = des.encrypt(message) # 连接数据库 conn = sqlite3.connect('mydatabase.db') c = conn.cursor() # 创建数据表 c.execute('''CREATE TABLE messages (id INTEGER PRIMARY KEY, message BLOB)''') # 将加密后的消息存储到数据库中 c.execute("INSERT INTO messages (message) VALUES (?)", (encrypted_message,)) conn.commit() # 从数据库中读取加密后的消息并解密 c.execute("SELECT message FROM messages") row = c.fetchone() encrypted_message_from_db = row[0] decrypted_message = des.decrypt(encrypted_message_from_db) # 输出解密后的消息 print(decrypted_message.decode()) ``` 希望这可以帮助你开始使用DES算法进行通信并将数据存储到Python数据库中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值