aboutsummaryrefslogtreecommitdiff
path: root/tests/performance/08_floyd-1.sy
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.001@gmail.com>2026-09-15 08:16:43 +0800
committerRichard Qin <richard.qin.001@gmail.com>2026-09-15 08:16:43 +0800
commit4022e5c95210631e4aceb08eaf9d9071aa5aefc4 (patch)
treea5922559836e45fb3459a3d070367912e1035b1a /tests/performance/08_floyd-1.sy
downloadrcc-4022e5c95210631e4aceb08eaf9d9071aa5aefc4.tar.gz
rcc-4022e5c95210631e4aceb08eaf9d9071aa5aefc4.tar.xz
Set up a git repoHEADmaster
Diffstat (limited to 'tests/performance/08_floyd-1.sy')
-rw-r--r--tests/performance/08_floyd-1.sy67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/performance/08_floyd-1.sy b/tests/performance/08_floyd-1.sy
new file mode 100644
index 0000000..2f00952
--- /dev/null
+++ b/tests/performance/08_floyd-1.sy
@@ -0,0 +1,67 @@
+const int maxlen = 2097152;
+int temp[maxlen], w[maxlen], dst[maxlen], c[maxlen];
+
+int getvalue(int a[], int n, int i, int j)
+{
+ if (i < 0 || i >= n || j < 0 || j >= n) return -1;
+ return a[i*n + j];
+}
+
+void mem_move(int src[], int dst[], int n){
+ int i = 0;
+ while (i < n){
+ dst[i] = src[i];
+ i = i + 1;
+ }
+}
+
+void floyd(int w[], int dst[], int n)
+{
+ int k = 0;
+ while (k < n) {
+ int i = 0;
+ while (i < n) {
+ temp[i*n + k] = getvalue(w, n, i, k);
+ i = i + 1;
+ }
+ k = k + 1;
+ }
+ k = 0;
+ while (k < n) {
+ int i = 0;
+ while (i < n) {
+ int j = 0;
+ while (j < n) {
+ if (getvalue(temp, n, i, k) >= 0 && getvalue(temp, n, k, j) >= 0) {
+ if (getvalue(temp, n, i, j) < 0) {
+ temp[i*n + j] = getvalue(temp, n, i, k) + getvalue(temp, n, k, j);
+ }
+ else {
+ if (temp[i*n + j] > getvalue(temp, n, i, k) + getvalue(temp, n, k, j)) {
+ temp[i*n + j] = getvalue(temp, n, i, k) + getvalue(temp, n, k, j);
+ }
+ }
+ }
+
+ j = j + 1;
+
+ }
+ i = i + 1;
+
+ }
+ k = k + 1;
+ }
+ mem_move(temp, dst, n*n);
+}
+
+int main()
+{
+ int n = getint();
+ getarray(w);
+
+ starttime();
+ floyd(w, dst, n);
+ stoptime();
+ putarray(n * n, dst);
+ return 0;
+}