UValive4255 Guess

2024-01-10 02:38
文章标签 guess uvalive4255

本文主要是介绍UValive4255 Guess,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

传送门
//放一个vjudge的罢

差分约束系统。

需要开一点点脑洞,转化为前缀和之间的大小关系然后建图跑拓扑排序。

CODE:(又长又丑又慢的代码)

#include<queue>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 15
struct edge
{int nxt,to,dis;
}a[10000];
char s[N][N];
int head[N],dis[N],in[N];
int T,n,num;
queue<int> q;
inline int max(const int &a,const int &b){return a>b?a:b;}
inline void add(int x,int y,int z)
{a[++num].nxt=head[x],a[num].to=y,a[num].dis=z,head[x]=num;
}
inline void topologysort()
{for(int i=0;i<=n;i++)if(!in[i]) q.push(i),dis[i]=0;while(!q.empty()){int tmp=q.front();q.pop();for(int i=head[tmp];i;i=a[i].nxt){dis[a[i].to]=max(dis[a[i].to],dis[tmp]+a[i].dis);in[a[i].to]--;if(!in[a[i].to]) q.push(a[i].to);}}
}
int main()
{scanf("%d",&T);while(T--){num=0;memset(head,0,sizeof(head));scanf("%d",&n);for(int i=0;i<=n;i++)dis[i]=0;for(int i=n;i;i--)for(int j=n-i+1;j<=n;j++){char c=getchar();while(c!='+'&&c!='-'&&c!='0') c=getchar();s[n-i+1][j]=c;}for(int i=1;i<=n;i++)for(int j=i;j<=n;j++)if(s[i][j]=='+') add(i-1,j,1),in[j]++;else if(s[i][j]=='-') add(j,i-1,1),in[i-1]++;else add(i-1,j,0),in[j]++;topologysort();for(int i=1;i<=n;i++)printf("%d ",dis[i]-dis[i-1]);puts("");}return 0;
}

这篇关于UValive4255 Guess的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/589282

相关文章

UVALive 4255 Guess

题意: 给你半个矩阵  如果(i,j)的位置是'-'  则说明sum[i...j]<0  如果是'+'  说明sum>0  如果是'0'  说明sum=0  给出一种满足这个矩阵的序列  序列元素绝对值在10以内 思路: 很容易想到的是将sum[i...j]转化为sum[j]-sum[i-1]  即用前缀和来表示  那么题中的矩阵就可以转化成前缀和之间的大小比较  也就是说  我们可以通过

UVA11995I Can Guess the Data Structure!(stack + queue + priority_queue)

题目:UVA11995I Can Guess the Data Structure!(stack + queue + priority_queue) 题目大意:给你两种指令,1代表让1后面的数字进入这个数据结构,2代表无差错的从数据结构中取出这个数字,问这个数据结构是stack还是queue还是priority_queue,还是不确定,还是以上均不可能。 解题思路:用STL中的这些

LeetCode-374. Guess Number Higher or Lower

问题:https://leetcode.com/problems/guess-number-higher-or-lower/?tab=Description We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to guess which number I pi

UVA - 11995 I Can Guess the Data Structure!

题意:求满足操作的数据结构 思路:模拟 #include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <stack>#include <queue>using namespace std;int n,o,e,cs,s,q,pq;int main(){while (scanf("%

Codeforces Round #312 (Div. 2) D. Guess Your Way Out! II 贪心排序

D. Guess Your Way Out! II time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Amr bought a new video game “Guess Your Way Out! II”. The goal

Codeforces Round #287 (Div. 2) C. Guess Your Way Out! 数学

C. Guess Your Way Out! time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Amr bought a new video game “Guess Your Way Out!”. The goal of the

【leetcode73】经典算法-Guess Number Higher or Lower

题目描述: 从1~n中,随便的拿出一个数字,你来猜测。 提示 提供一个guess(int num)的api,针对猜测的数字,返回三个数值。0,-1,1 0;猜中返回num-1:比猜测的数值小1:比猜测的数值大 例如: n = 10, I pick 6. Return 6. 原文描述: We are playing the Guess Game. The game is as fo

checking build system type... configure: error: cannot guess build type; you must specify one

今天在用configure生成Makefile时,出现了如下错误: checking build system type... configure: error: cannot guess build type; you must specify one 我用的命令是./configure --host=arm-linux- --prefix=/txk/build/install 根

[CF_1282D]Guess the Root

Guess the Root 题解 拉格朗日板题 按理说只要n+1个点就可以表示出一个n阶的多项式,对于求法很容易想到高斯消元。 但高斯消元法太麻烦了,于是,我们便开始了拉格朗日插值法。因为它更方便。 拉格朗日插值法可以通过点值求出原式,即。 将所有的点带入后就成了一个关于的多项式,从到枚举即可。 源码 一个忘了在外面预处理inv的蒟蒻   #pragma GCC optimi

Guess The Number

首先判断一下无意义的情况: 1.最高位数字为零(n=1除外); 2.读入数字大于n; 3.前面已读入第i位且与当前读入数不相同; 以上情况直接输出-1 还需要判断一种情况,当最高位数字并未指定,则需将最高位赋值1 将所有位数字初始为0,这样便是满足条件的最小数 接下来便是将其依次输出