摘要:题目大意:有一些简单的化合物,每个化合物由两种元素组成,把这些化合物按顺序装车,若k个化合物正好包含k种元素,那么就会爆炸。避免爆炸,有些化合物就不能装车。求有多少个不能装车。题目分析:若k个化合物正好包含k种元素,那么就会爆炸。我们把每种元素看成一个顶点,每种化合物看成一条边,若有环存在的时候正好是爆炸的情况,所以避免成环记录不能放的数量就行了。#include#includeusing namespace std;const int maxn=100010;int f[maxn];int findset(int x){ return f[x]==x?x:f[x]=findset(f[x])
阅读全文
摘要:K Smallest SumsYou're given k arrays, each array has k integers. There are kkways to pick exactly one element in each array and calculate the sum of the integers. Your task is to find the k smallest sums among them.InputThere will be several test cases. The first line of each case contains an in
阅读全文
摘要:题目大意:有若干命令,它有两个属性Q_Num,Period(周期)。按时间循序模拟前k个命令并输出他们的Q_Num,若同时发生输出Q_Num最小的值。#include#include#include#includeusing namespace std;struct Item{ int QNum,Period,Time; bool operator pq; while(scanf("%s",s) && s[0] != '#') { scanf("%d %d",&item.QNum,&item.Period)
阅读全文
摘要:题目大意:一个n个整数的数组,m条查询指令。(1#include#include#includeusing namespace std;map > a;int main(){ int n,m,i,p,k,v; while(scanf("%d %d",&n,&m) == 2) { a.clear(); for(i=0;i (); a[p].push_back(i+1); } while(m--) { scanf("%d %d",&k,&v); ...
阅读全文
摘要:Problem II Can Guess the Data Structure!There is a bag-like data structure, supporting two operations:1 xThrow an element x into the bag.2Take out an element from the bag.Given a sequence of operations with return values, you're going to guess the data structure. It is a stack (Last-In, First-Ou
阅读全文