Beispiel #1
0
int main()
{
	freopen("iq.in", "r", stdin);
	freopen("iq.out", "w", stdout);
	while(scanf("%d", &n) == 1 && n)
	{
		for(int i = 1; i <= n; i++)
		{
			scanf("%d", &a[i].a);
			a[i].idx = i;
			dp[i] = 0x3f3f3f3f3f3f3f3fll;
			pre[i] = -1; g[i] = 0;
		}
		dp[0] = 0; pre[0] = -1; g[0] = 0;
		std::sort(a+1, a+1+n);
		for(int i = 1; i <= n; i++)
			for(int j = 0; j < i; j++)
			{
				long long tmp = dp[j] + 1ll * a[i].a * (n - j);
				if(tmp < dp[i])
				{
					dp[i] = tmp;
					pre[i] = j; g[i] = g[j] + 1;
				}
			}
		printf("%I64d\n", dp[n]);
		printf("%d\n", g[n]);
		printAns(n);
	}
	return 0;
}
Beispiel #2
0
void solve() {
    string s;
    getline(cin, s);
    shared_ptr < Node > head = parse(s);
    map < string, string > q;
    string answer = rec(head, q);
    //cerr << genAns(head) << endl;
    //for (auto x: G) {
        //cerr << x.fr << " =  " << x.sc << endl;
    //}
    //for (auto x: varId) {
        //cerr << x.fr << ": " << x.sc << endl;
    //}

    go();
    //db(answer);
    //for (auto x: G) {
        //cerr << x.fr << " =  " << x.sc << endl;
    //}
    
    for (int i = 0; i < (int)G.size(); i++) {
        if (G[i].fr->type == answer) {
            cerr << "result:   " << printAns(G[i].sc) << endl;
        }
    }

    //cout << g[id]->toString() << endl;
    for (auto x: varId) {
        cout << x.fr << ":" << x.sc << endl;
    }
}
Beispiel #3
0
int main(int argc, char *argv[]) {

	int length;
	int index = 0;
	int *indexPointer = &index;
	int amt = 0;

	if (argc == 1) {
		length = 10;
	}

	else {
		argv++;
		sscanf(*argv,"%d",&length);
	}

	//printf("%d\n",length);
	int *array = (int *) malloc(length * sizeof(int));

	while (1) {

		int val;
		scanf("%d", &val);

		if (val == -1) {
			break;
		}

		amt++;
		addToHeap(array,val,indexPointer,length);
	}

	printAns(array, index, length, amt);
	free(array);
}
Beispiel #4
0
void printAns(int i)
{
	if(pre[i] == -1) return;
	printAns(pre[i]);
	printf("%d", i - pre[i]);
	for(int k = pre[i] + 1; k <= i; k++) printf(" %d", a[k].idx);
	puts("");
}
void printAns(int n, int now, int slen) {
	if(Node[now].n != 0) {
		buf[slen] = '\0';
		printf("%s %.4f\n", buf, Node[now].n*100.0/n);
	}
	int i;
	for(i = 0; i < 128; i++) {
		if(Node[now].link[i] != 0) {
			buf[slen] = i;
			printAns(n, Node[now].link[i], slen+1);
		}
	}
}
int main()
{
	int T;

	scanf("%d", &T);
	
	while(T--)
	{
		char str[1001];

		scanf("%s", str);
		printAns(str);
	}
	return 0;
}
int main() {
	int t;
	char buf[35];
	scanf("%d", &t);
	getchar();
	getchar();
	while(t--) {
		int n = 0;
		memset(&Node[0], 0, sizeof(Node[0]));
		TrieSize = 0;
		while(gets(buf)) {
			if(buf[0] == '\0')	
				break;
			insertTrie(buf);
			n++;
		}
		printAns(n, 0, 0);
		if(t)
			puts("");
	}
    return 0;
}
Beispiel #8
0
void doArea(int a,int b,int c)
{
	float s = (a+b+c)/2;
	float ans = sqrt((s-a)*(s-b)*(s-c));
	printAns(ans);
}
Beispiel #9
0
void doPeri(int a,int b,int c)
{
	printAns(a+b+c);
}
Beispiel #10
0
void doDiv(int a,int b)
{
	printAns(a/(float)b);
}
Beispiel #11
0
void doMult(int a,int b)
{
	printAns(a*b);
}
Beispiel #12
0
void doSub(int a,int b)
{
	printAns(a-b);
}
Beispiel #13
0
void doAdd(int a,int b)
{
	printAns(a+b);
}
Beispiel #14
0
string printAns(shared_ptr < TNode > v) {
    if (v->checkVar()) {
        return v->type;         
    }
    return "(" + printAns(v->ch[0]) + "->" + printAns(v->ch[1]) + ")";  
}