丰收?

(忘了题目了QAQ)

题目描述:

又到了丰收的季节,恰逢小易去牛牛的果园里游玩。
牛午常说他对整个果园的每个地方都了如指掌,小易不太相信,
所以他想考考牛牛。
在果园里有N堆苹果,每堆苹果的数量为ai,小易希望知道从左往
右数第x个苹果是属于哪一堆的。
牛牛觉得这个问题大简单,所以希望你来着他回答。

输入描述:

第一行一个数n(1<=n<=100000)
第二行n个数ai(1<=ai<=1000),表示从左往右数第i堆有多少苹果
第三行一个数m(1<=m<=100000),表示有m次询口。
第四行m个数,表示小易希望知道第qi个苹果属于哪一堆。
 

测试样例:

5
2 7 3 4 9
3
1 25 11

输出

1

5

3

思路:

前缀和+二分

第i个位置表示前i堆苹果总数量,利用二分查找输入苹果所在的位置

代码:

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <queue>
#include <map>
#include <list>
#include <utility>
#include <set>
#include <algorithm>
#include <deque>
#include <vector>
#define IO ios::sync_with_stdio(false);\
        cin.tie();\
        cout.tie();
using namespace std;
typedef long long ll;
typedef vector<int > vi;
const ll INF = 0x3f3f3f3f;
;
 + ;
int a[MAX];
int front_a[MAX];
int main()
{
    int n,m;
    scanf("%d",&n);
     ; i <= n; i++)
    {
        scanf("%d", a + i );
        front_a[i] = front_a[i-] + a[i];
    }
    scanf("%d",&m);
    while(m--) {
        int q;
        scanf("%d",&q);
        ,right = n;

        while(left < right) {
            ;
            if(front_a[middle] < q )
            {
                left = middle+;
            }
            else if(front_a[middle]>q){
                right = middle;
            }else {
                left = middle;
                break;
            }
        }
        printf("%d\n",left);
    }
    ;
}
/*
5
2 7 3 4 9
3
1 25 11
*/

题目描述

小易有一些立方体,每个立方体的边长为1,他用这些立方体搭了一些塔
现在小男定义:这些场的不稳定值为它们之中最高的塔与最低的塔的高度差,
小易想让这些塔尽量稳定,所以他进行了如下操作:每次从基座楼上取下块立方体并把它到号空塔上,
注意,小题不会把立方体放到它原本的那座塔上,因为他认为这样无意义

输入描述

第一行一个n(1<=n<=100),一个k(1<=k<=1000)

第二行ai(1<=ai<=10000)代表每个塔的高度

输出描述

第一行输出一个s,一个m,s代表最低的不稳定性,m为操作步数

接下来m行每行代表a塔向b塔移动一个单位

测试样例:

样例输入:

3 2
5 8 5

样例输出

0 2

2 1

2 3

思路:

因为数据量不大,全程模拟,先将所有的塔从低到高排序 将最高塔移动一个单位给最低塔 再排序移动 最多循环k次

如果最低与最高塔的差小于等于1,直接退出。

PS:描述可能有差池,请见谅 还有 这仅代表个人思路 笔试过程中仅通过20%(听说此题已重判,故妄自菲薄的贴上代码,望大神指正)

代码:

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <queue>
#include <map>
#include <list>
#include <utility>
#include <set>
#include <algorithm>
#include <deque>
#include <vector>
#define IO ios::sync_with_stdio(false);\
        cin.tie();\
        cout.tie();
using namespace std;
typedef long long ll;
typedef vector<int > vi;
const ll INF = 0x3f3f3f3f;
;
 + ;
typedef struct node {
    int pos;
    int high;
} node;
node High[N];
bool cmp(node a , node b) {
    return a.high < b.high;
}
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    ; i <= n; i++) {
        scanf("%d",&High[i].high);
        High[i].pos = i;
    }
    queue <pair<int,int> > q;
    ,num = ;
    sort(High +  , High+n+,cmp);
    ;
     ; i < k; i++) {

        ].high<=) {
            value = High[n].high - High[].high;
            flag = ;
            break;
        }else {
            High[n].high--;
            High[].high++;
            num++;
            q.push(pair<].pos));
        }
        sort(High +  , High+n+,cmp);
    }
    ) {
        value = High[n].high - High[].high;
    }
    printf("%d %d\n",value,num);
    while(!q.empty()) {
        int x = q.front().first;
        int y = q.front().second;
        q.pop();
        printf("%d %d\n",x,y);
    }
    ;
}
/*
3 2
5 8 5*/

整理房间

题目描述

又到了周末,小易的房间乱得一团糟。
他希望将地上的杂物稍微整理下,使每团杂物看起来都紧凑一些, 没有那么乱。
地上一共有n团杂物,毎团杂物都包含4个物品。第i物品的坐标用(ai,bi)表示,小易毎次都可以将
它绕着(xi,yi)逆时针旋转90°,这将消耗他的一次移动次数。如果一团杂物的4个点构成了一个面
积不为0的正方形,我们说它是紧凑的。
因为小易很懒,所以他希望你帮助他计算一下每团杂物最少需要多少步移动能使它変得紧凑。

输入描述

第一行一个数(1 <= n <= 100),表示杂物的团数。
接下来4n行,毎4行表示一团杂物,毎行4个数xi, yi, ai, bi(-10^4<= xi, yi,
ai,bi <= 10^4),表示第i个物品旋转的中心点坐标和它本身的坐标。
輸出描述:
n行,毎行1个数,表示最少移动次数。

示例1
输入
4
1 1 0 0
-1 1 0 0
-1 1 0 0
1 -1 0 0
-2 1 0 0
-1 1 0 0
1 -1 0 0
1 1 0 0
-1 1 0 0
-1 1 0 0
-1 1 0 0
2 2 0 1
-1 0 0 -2
3 0 0 -2
-1 1 -2 0
输出
1
-1
3
3

说明
对于第一团杂物,我们可以旋转第二个或者第三个物品1次。

思路:

暴力枚举每团杂物4 ^ 4次旋转

代码:

来自牛客大神的代码。

作者:NotDeep
链接:https://www.nowcoder.com/discuss/92989?type=0&order=0&pos=6&page=0
来源:牛客网

#include <bits/stdc++.h>
using namespace std; 
struct point {
    int x, y;
    point(, ) : x(x), y(y) {}
    point operator+(const point &rhs) const {
        return point(x + rhs.x, y + rhs.y);
    }
    point operator-(const point &rhs) const {
        return point(x - rhs.x, y - rhs.y);
    }
    point rotate() { return point(-y, x); }
    point rotate(const point &o) const { return o + (*this - o).rotate(); }
    bool operator==(const point &rhs) const { return x == rhs.x && y == rhs.y; }
};
 
bool check(const point &a, const point &b) {
     && a.y ==  || b.x ==  && b.y == ) return false;
    if (a.x * a.x + a.y * a.y != b.x * b.x + b.y * b.y) return false;
    ) return false;
    return true;
}
 
int main() {
    int n;
    cin >> n;
    while (n--) {
        point p[], o[], a[];
        ; i < ; i++)
            scanf("%d %d %d %d", &p[i].x, &p[i].y, &o[i].x, &o[i].y);
        ;
        int x, y, z, w;
        , a[] = p[]; x < ; x++) {
            , a[] = p[]; y < ; y++) {
                , a[] = p[]; z < ; z++) {
                    , a[] = p[]; w < ; w++) {
                        int cost = x + y + z + w;
                        ] + a[] == a[] + a[] &&
                                check(a[] - a[], a[] - a[]) ||
                            a[] + a[] == a[] + a[] &&
                                check(a[] - a[], a[] - a[]) ||
                            a[] + a[] == a[] + a[] &&
                                check(a[] - a[], a[] - a[])) {
                             || res > cost) res = cost;
                        }
                        a[] = a[].rotate(o[]);
                    }
                    a[] = a[].rotate(o[]);
                }
                a[] = a[].rotate(o[]);
            }
            a[] = a[].rotate(o[]);
        }
        printf("%d\n", res);
    }
    ;
}

最新文章

  1. UP Board 人若有大胆,板子就很惨:首次上电开机失败
  2. String Aop 动态代理例子
  3. 2014年百度之星程序设计大赛 - 初赛(第二轮)JZP Set
  4. spring @condition 注解
  5. spring 注入静态变量
  6. isNaN() 确认是否是数字
  7. SQL Server中DateTime与DateTime2的区别
  8. iOS开发项目之三 [ 自定义tabBarCtrl]
  9. OpenShare新功能@2014年11月 [2014-11-30]
  10. php 获取远程图片
  11. servlet清晰理解
  12. Java日期时间使用(转)
  13. rm-rf 恢复过程中滥用
  14. RoportNG报表显示中文乱码和TestNG显示中文乱码实力解决办法
  15. 动手动脑(lesson2)
  16. aws ubuntu 开启root
  17. windows系统显示隐藏文件以及显示文件扩展名
  18. 使用vue做项目
  19. 记一次Apache Carbondata PR的经历
  20. Sun公司的产品AnswerBook存在多种漏洞

热门文章

  1. uva 11424
  2. sgu 131 状压DP
  3. BigBlueButton简介
  4. UBOOT启动内核过程
  5. 概率dp+期望dp 题目列表(一)
  6. PowerDesigner16 时序图
  7. 图书馆排序(Library Sort)
  8. 基本控件文档-UISegment属性----iOS-Apple苹果官方文档翻译
  9. 【转载】VS2013安装需要IE10
  10. spring项目中web-inf下不能引用页面资源