我他妈怎么这么菜

昨天千里万里跑回学校打那个网络赛,然并卵,没有拿到现场赛资格。
今天花了一下午一晚上时间学习树状数组,lowbit函数取x&(-x)即可得x的二进制从右往左第一个1的位置,add函数用来修改一个值以及所有包含这个元素节点的值,quiry查询是为了获得a[1]+a[2]+??????+a[x]的值,那么这个题的quiry就是找的以前的最大值加上当前的值。
YJJ‘s Salesman
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1126 Accepted Submission(s): 389

Problem Description

YJJ is a salesman who has traveled through western country. YJJ is always on journey. Either is he at the destination, or on the way to destination.
One day, he is going to travel from city A to southeastern city B. Let us assume that A is (0,0) on the rectangle map and B (109,109). YJJ is so busy so he never turn back or go twice the same way, he will only move to east, south or southeast, which means, if YJJ is at (x,y) now (0≤x≤109,0≤y≤109), he will only forward to (x+1,y), (x,y+1) or (x+1,y+1).
On the rectangle map from (0,0) to (109,109), there are several villages scattering on the map. Villagers will do business deals with salesmen from northwestern, but not northern or western. In mathematical language, this means when there is a village k on (xk,yk) (1≤xk≤109,1≤yk≤109), only the one who was from (xk?1,yk?1) to (xk,yk) will be able to earn vk dollars.(YJJ may get different number of dollars from different village.)
YJJ has no time to plan the path, can you help him to find maximum of dollars YJJ can get.

Input

The first line of the input contains an integer T (1≤T≤10),which is the number of test cases.

In each case, the first line of the input contains an integer N (1≤N≤105).The following N lines, the k-th line contains 3 integers, xk,yk,vk (0≤vk≤103), which indicate that there is a village on (xk,yk) and he can get vk dollars in that village.
The positions of each village is distinct.

Output

The maximum of dollars YJJ can get.

Sample Input

1
3
1 1 1
1 2 2
3 3 1

Sample Output

3

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define lowbit(x) x&(-x)
const int mod = 1e9+7;
const int mx =     1e5+5;
typedef long long ll;
int x[mx];
int n;
ll sum[mx];
void add(int p,ll x){
    while(p<=n){
        sum[p] = max(sum[p],x);
        p += lowbit(p);
    }
}
ll query(int p){
    ll ans = 0;
    while(p){
        ans = max(ans,sum[p]);
        p -= lowbit(p);
    }
    return ans;
}
struct node{
    int x,y;
    ll w;
    bool operator<(const node &a)const{
        if(y != a.y) return y < a.y;
        return x > a.x;
    }
}a[mx];
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        for(int i = 1; i <= n; i++){
            scanf("%d%d%lld",&a[i].x,&a[i].y,&a[i].w);
            x[i] = a[i].x;
            sum[i] = 0;
        }
        sort(a+1,a+n+1);
        sort(x+1,x+n+1);
        ll res = 0;
        for(int i = 1; i <= n; i++){
            int k = lower_bound(x+1,x+n+1,a[i].x)-x;
            ll ans = a[i].w+query(k-1);
            add(k,ans);
            res = max(ans,res);
        }
        printf("%lld\n",res);
    }
    return 0;
}

还有一个题是pzr在做,但是他没过。。。

emmm这个题我们考虑一个新的物品跟小根堆的堆顶比较,如果新物品比堆顶还小,说明交易亏本,直接丢入堆中,否则就交易,如果堆顶的元素是已经跟之前交易过的,那么就相当于当前物品和之前那个交易,然后堆顶就变成没有交易了,继续插入堆中,交换次数不变,如果堆顶是没有交易过的,那么就交易,交易次数+2.我们希望交换次数尽可能的小,那么价值相同是,已经交换过得就有限辣

Buy and Resell

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1319    Accepted Submission(s): 434

Problem Description

The Power Cube is used as a stash of Exotic Power. There are n

cities numbered 1,2,…,n

where allowed to trade it. The trading price of the Power Cube in the i

-th city is ai

dollars per cube. Noswal is a foxy businessman and wants to quietly make a fortune by buying and reselling Power Cubes. To avoid being discovered by the police, Noswal will go to the i

-th city and choose exactly one of the following three options on the i

-th day:

1. spend ai

dollars to buy a Power Cube
2. resell a Power Cube and get ai

dollars if he has at least one Power Cube
3. do nothing

Obviously, Noswal can own more than one Power Cubes at the same time. After going to the n

cities, he will go back home and stay away from the cops. He wants to know the maximum profit he can earn. In the meanwhile, to lower the risks, he wants to minimize the times of trading (include buy and sell) to get the maximum profit. Noswal is a foxy and successful businessman so you can assume that he has infinity money at the beginning.

Input

There are multiple test cases. The first line of input contains a positive integer T

(T≤250

), indicating the number of test cases. For each test case:
The first line has an integer n

. (1≤n≤105

)
The second line has n

integers a1,a2,…,an

where ai

means the trading price (buy or sell) of the Power Cube in the i

-th city. (1≤ai≤109

)
It is guaranteed that the sum of all n

is no more than 5×105

.

Output

For each case, print one line with two integers —— the maximum profit and the minimum times of trading to get the maximum profit.

Sample Input

3

4

1 2 10 9

5
9 5 9 10

5
2
2 1

Sample Output

16 4

5 2

0 0

Hint

In the first case, he will buy in 1, 2 and resell in 3, 4. profit = - 1 - 2 + 10 + 9 = 16
In the second case, he will buy in 2 and resell in 4. profit = - 5 + 10 = 5
In the third case, he will do nothing and earn nothing. profit = 0

#include <iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<queue>
#include<algorithm>
using namespace std;
struct node
{
    int num;
    int flag;
    node()
    {

    };
    node(long long a,long long b)
    {
        num=a;
        flag=b;
    }
};
bool operator <(node a,node b)
    {
        if(a.num==b.num)
            return a.flag>b.flag;
        return a.num>b.num;
    }
int main()
{
   int t,temp,i;
   int n;
   cin>>t;
   while(t--)
   {
       long long cnt=0,sum=0;
       cin>>n;
        priority_queue<node>que;
       for(i=1;i<=n;i++)
       {
       cin>>temp;
       if(que.empty())
       {
            que.push(node(temp,1));
            continue;
       }
        node ans=que.top();
       if(temp>ans.num)
       {
           sum+=temp-ans.num;
           if(ans.flag==1)
            cnt+=2;
            que.pop();
            que.push(node(temp,0));
        }
        que.push(node(temp,1));
       }
       cout<<sum<<" "<<cnt<<endl;
       while(!que.empty())
       {
           que.pop();
       }
   }
   return 0;
}

这个题,,,一直超时最后他们跟我说根据费马小定理n>2的情况根本不存在,哭唧唧。

然后还有个什么勾股定理也可以简单判,那个定理长这样

所以说这道题其实是一道非常简单的题辣!

Find Integer

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1142    Accepted Submission(s): 313
Special Judge

Problem Description

people in USSS love math very much, and there is a famous math problem .

give you two integers n

,a

,you are required to find 2

integers b

,c

such that an

+bn=cn

.

Input

one line contains one integer T

;(1≤T≤1000000)

next T

lines contains two integers n

,a

;(0≤n≤1000

,000

,000,3≤a≤40000)

Output

print two integers b

,c

if b

,c

exits;(1≤b,c≤1000

,000

,000)

;

else print two integers -1 -1 instead.

Sample Input

1
2 3

Sample Output

4 5

#include <cstdio>
#include <iostream>
#include <cmath>
#include <map>
using namespace std;
int main()
{
    long long n;
    int a;
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lld %d",&n,&a);
        if(n>2) printf("-1 -1\n");
        else if(n==0) printf("-1 -1\n");
        else if(n==1) printf("1 %d\n",a+1);
        else {
            if(a==1||a==2) printf("-1 -1\n");
            else if(a%2==1){
                int sum=a*a;
                printf("%d %d\n",sum/2,sum/2+1);
            }
            else{
                int sum=a*a/2;
                printf("%d %d\n",sum/2-1,sum/2+1);
            }
        }
    }
    return 0;

}

呜呜呜,我好菜啊。

原文地址:https://www.cnblogs.com/kepa/p/9539234.html

时间: 2024-08-02 18:13:20

我他妈怎么这么菜的相关文章

获得他人体感

p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 36.0px "PingFang SC"; min-height: 50.0px } p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 36.0px "PingFang SC" } span.Apple-tab-span { white-space: pre } 3个人如何获得与他人相同的体感 人与人之间的体感是不一样的,造成的思想也

由我妈买菜,联想到了数据挖掘

记得以前看过一本数据挖掘的书籍,书籍开篇有一个小案例.就是一家超市发现每天尿布的销售量增加的时段同时啤酒也卖的特别好.后来研究发现,当地生活习惯是,老爸带孩子居多,所以买尿布的同时买了啤酒,所以这家超市就把啤酒和尿布还有其他年轻父亲需要的照顾孩子用的产品放在一起,方便这些奶爸购买.这就很方便,你想啊,超市很大.来换找想买的东西很麻烦这样就好多了.方便了消费者.同时用户会经常去这家买因为很方便省. 晚上和我妈吃饭.我发现有菜里很多菜叶,就问起,这时单独买的菜叶?我妈说超市不要的,都是其他买菜的人挑

卖菜也能有新招

实习时间:2016/02/05 ——2016/02/24 实习地点:广西省桂林市平乐县菜市 实习报告: 早早学校就放假了,当时也没有找到好的实习工作,所以就先回了家.回家回的早也有早的烦恼,当时朋友同学都还在上学没回家,爸妈就叫我去卖菜了.世界上没有任何事情是可以很轻松做完的,卖菜也一样.卖菜最烦的就是等待,最困的就是早起晚归. 头天下午就去菜地里面把要的菜和菜农们说好,等第二天一大早菜农们就会把菜送到我们卖菜的档口去. 这就是其中一天去地上看的菜. 第二天一大早就去搬菜.摆菜了. 枯燥而无谓的

开春多吃五大排毒菜!一整年都健康快乐~

开春多吃五大排毒菜!一整年都健康快乐~ 2016-03-03 黄瓜--清热促代谢 <本草纲目>中记载,黄瓜味甘性凉,有清热.解渴.利水.消肿的功效.对春季常见的烦躁.喉痛等症状,都有帮助. 现代医学认为,黄瓜中含有纤维素,对促进肠蠕动.加快排泄有一定作用.黄瓜所含的黄瓜酸,能促进人体的新陈代谢,排出毒素. 黄瓜的利尿作用能清洁尿道,有助于肾脏排出泌尿系统的毒素.鲜黄瓜内还含有丙醇二酸,可以抑制糖类物质转化为脂肪.但黄瓜偏寒,脾胃虚弱.久病者宜少吃. 黄瓜很适合用来凉拌,比如黄瓜木耳.蒜拌黄瓜等

菜鸟窝React Native 视频系列教程

菜鸟窝React Native 视频系列教程 交流QQ群:576089067 Hi,我是RichardCao,现任新美大酒店旅游事业群的Android Developer.15年加入饿了么即时配送BU,后负责蜂鸟众包Android端,期间引入react-native技术,作为国内react-native 与 Android混合开发的早期商业项目,具有一定经验,同时也是react-native开源项目reading(https://github.com/attentiveness/reading)

菜鸟窝React Native 系列教程-1.移动端开发趋势与未来

菜鸟窝React Native 系列教程-1.移动端开发趋势与未来 课程持续更新中..... 我是RichardCao,现任新美大酒店旅游事业群的Android Developer.如果你也有兴趣录制RN视频,请加入下面QQ群找我. 下载地址:https://pan.baidu.com/s/1c1XmE56 密码:shhw 首发地址:菜鸟窝-ReactNative学习板块 交流QQ群:576089067 课程目录:菜鸟窝React Native 系列教程

信息价产品经理日志(1)- 妈的,不想再呆在广联达了

前几天一个女同事看到我的一张名片说,周哥看起来还是蛮酷的.另一个男同事说,我们老大本来就很帅啊. 这是我的个人名片,我觉得酷的是,敏捷个人创始人.更酷的是,快乐.高效.平衡. 你快乐吗?你高效吗?你平衡吗?如果你正在迷茫中,那就跟着敏捷个人一起成长吧. 关于敏捷个人的话题,我说了太多了,网上也可以找到很多资料,能否学到精髓就看你的学习能力了.当然,你要是觉得一年300元对你来说是一笔可以做出的个人学习投资的话,那也不要犹豫加入我们的年费会员(购买加入)啊. 也许你说,我怎么在产品经理日志上也讲敏

&lt;鸟哥的Linux私房菜 第二版 读书笔记 &gt;

2017年4月9日22:23:40 <鸟哥的linux私房菜> 1.操作系统 1.1什么是操作系统呢? 操作系统是用来管理计算机的软硬件资源,用来方便用户使用的程序的集合.让用户不必要在了解硬件的作用只需要简单的操作就可以完成复杂的计算问题. 1.2Kernel Kernel(核心),是计算机操作系统的内核,是操作系统的核心部分,也是操作系统最底层的东西,它掌管着整个硬件资源的工作状态. 核心管理的事项主要有:系统调用接口(System Call Interface).进程控制(Process

设计一款给爸妈用的手机

一.需求分析 考虑到父母大多是70后的,工作时会接触到很多同事,并且现在的人越来越追求时尚,所以我们组为爸妈设计了一款以“智能.简单.健康”为设计理念的手机. 二.组内分工 蒋欣负责外形设计,顾艳娜负责草图绘画和功能记录,高志敏和钱箭羽设计手机功能. 三.外形设计 1.开关键,我们把开关键设在手机的下方正中央. 2.求救键,我们把紧急键设在左下方,紧急键是在遇到危险情况时用来拨打紧急电话以及SOS的. 3.亲情号码,我们把亲情拨号快捷键设在右下方,按下拨号键可以弹出设置了的子女号码:例如1代表女