CF_2018-2019 Russia Open High School Programming Contest (Unrated, Online Mirror, ICPC Rules, Teams Preferred)

只做了两个就去上课去啦...
A. Company Merging
time limit per test
1 second
memory limit per test
512 megabytes
input
standard input
output
standard output

A conglomerate consists of nn companies. To make managing easier, their owners have decided to merge all companies into one. By law, it is only possible to merge two companies, so the owners plan to select two companies, merge them into one, and continue doing so until there is only one company left.

But anti-monopoly service forbids to merge companies if they suspect unfriendly absorption. The criterion they use is the difference in maximum salaries between two companies. Merging is allowed only if the maximum salaries are equal.

To fulfill the anti-monopoly requirements, the owners can change salaries in their companies before merging. But the labor union insists on two conditions: it is only allowed to increase salaries, moreover all the employees in one company must get the same increase.

Sure enough, the owners want to minimize the total increase of all salaries in all companies. Help them find the minimal possible increase that will allow them to merge companies into one.

Input

The first line contains a single integer nn — the number of companies in the conglomerate (1n21051≤n≤2⋅105). Each of the next nn lines describes a company.

A company description start with an integer mimi — the number of its employees (1mi21051≤mi≤2⋅105). Then mimi integers follow: the salaries of the employees. All salaries are positive and do not exceed 109109.

The total number of employees in all companies does not exceed 21052⋅105.

Output

Output a single integer — the minimal total increase of all employees that allows to merge all companies.

Example
input
Copy
3
2 4 3
2 2 1
3 1 1 1
output
Copy
13
Note

One of the optimal merging strategies is the following. First increase all salaries in the second company by 22, and merge the first and the second companies. Now the conglomerate consists of two companies with salaries [4,3,4,3][4,3,4,3] and [1,1,1][1,1,1]. To merge them, increase the salaries in the second of those by 33. The total increase is 2+2+3+3+3=132+2+3+3+3=13.

思路:一个大集团下面有n个公司,每个公司m个员工,每个员工的工资mi,现在要合并公司.两两合并,最后只剩一个才行,合并要求是,两个公司之间的员工最大工资相等才行.

只要记录每个公司的最大工资,然后排序,再开始从小到大挨着两两合并.

#include <iostream>
#include <algorithm>
#include <cstdlib>

using namespace std;

struct everycom{
        int maxx;
        int num;
};

struct everycom ec[1000005];

int cmp(struct everycom a,struct everycom b){
        return a.maxx<b.maxx;
}

int main(){
        int n,m;
        int now=0;
        int maxx=0;
        //while(scanf("%d",&n)){
        scanf("%d",&n);
                long long sum=0;
                long long nownum=0;
                for(int i=0;i<n;i++){
                        cin>>m;
                        ec[i].num=m;
                        maxx=0;
                        for(int j=0;j<m;j++){
                                cin>>now;
                                maxx=now>maxx?now:maxx;
                        }
                        ec[i].maxx=maxx;
                }
                sort(ec,ec+n,cmp);
                for(int i=0;i<n-1;i++){
                        long long tmp=ec[i+1].maxx-ec[i].maxx;
                        nownum+=ec[i].num;
                        sum+=tmp*nownum;
                }
                cout<<sum<<endl;
}
View Code

M. The Pleasant Walk

time limit per test
1 second
memory limit per test
512 megabytes
input
standard input
output
standard output

There are nn houses along the road where Anya lives, each one is painted in one of kk possible colors.

Anya likes walking along this road, but she doesn't like when two adjacent houses at the road have the same color. She wants to select a long segment of the road such that no two adjacent houses have the same color.

Help Anya find the longest segment with this property.

Input

The first line contains two integers nn and kk — the number of houses and the number of colors (1n1000001≤n≤100000, 1k1000001≤k≤100000).

The next line contains nn integers a1,a2,,ana1,a2,…,an — the colors of the houses along the road (1aik1≤ai≤k).

Output

Output a single integer — the maximum number of houses on the road segment having no two adjacent houses of the same color.

Example
input
Copy
8 3
1 2 3 3 2 1 2 2
output
Copy
4
Note

In the example, the longest segment without neighboring houses of the same color is from the house 4 to the house 7. The colors of the houses are [3,2,1,2][3,2,1,2] and its length is 4 houses.

思路:让找最长的序列,序列中任何两个相邻的元素不能相等.

#include <iostream>

using namespace std;

int main(){
        int n,k;
        //int a[100005];
        int ai;
        while(cin>>n>>k){
                int la=0;
                int now=1;
                int maxx=1;
                cin>>ai;
                la=ai;
                for(int i=1;i<n;i++){
                        //cin>>a[i];
                        cin>>ai;
                        if(ai!=la){
                                now++;
                        }else{
                                now=1;
                        }
                        la=ai;
                        maxx= now>maxx?now:maxx;
                }
                cout<<maxx<<endl;
        }
}

 

 

 

 

 

全部评论

相关推荐

会飞的猿:我看你想进大厂,我给你总结一下学习路线吧,java语言方面常规八股要熟,那些java的集合,重点背hashmap八股吧,jvm类加载机制,运行时分区,垃圾回收算法,垃圾回收器CMS、G1这些,各种乐观锁悲观锁,线程安全,threadlocal这些。在进阶一些的比如jvm参数,内存溢出泄漏排查,jvm调优。我这里说的只是冰山一角,详细八股可以去网上找,这不用去买,都免费资源。mysql、redis可以去看小林coding,我看你简历上写了,你一定要熟,什么底层b+树、索引结构、innodb、mvcc、undo log、redo log、行级锁表级锁,这些东西高频出现,如果面试官问我这些我都能笑出来。消息队列rabbitmq也好kafka也好,学一种就行,什么分区啊副本啊确认机制啊怎么保证不重复消费、怎么保证消息不丢失这些基本的一定要会,进阶一点的比如LEO、高水位线、kafka和rocketmq底层零拷贝的区别等等。计算机网络和操作系统既然你是科班应该理解起来问题不大,去看小林coding这两块吧,深度够了。spring boot的八股好好看看吧,一般字节腾讯不这么问,其他的java大厂挺爱问的,什么循环依赖啥的去网上看看。数据结构的话科班应该问题不大,多去力扣集中突击刷题吧。项目的话其实说白了还是结合八股来,想一想你写的这些技术会给你挖什么坑。除此之外,还有场景题、rpc、设计模式、linux命令、ddd等。不会的就别往简历上写了,虽然技术栈很多的话好看些,但背起来确实累。总结一下,多去实习吧,多跳槽,直到跳到一个不错的中厂做跳板,这是一条可行的进大厂的路线。另外,只想找个小厂的工作的话,没必要全都照这些准备,太累了,重点放在框架的使用和一些基础八股吧。大致路线就这样,没啥太多难度,就是量大,你能达到什么高度取决于你对自己多狠,祝好。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务