2020年5月24日日曜日

Error in Matrix Makert IO function (C)

I feel that there is an error in I/O functions of the Matrix Market Routine (https://math.nist.gov/MatrixMarket/mmio-c.html) .

mm_is_* functions in mmio.h expects that descriptions in matrix files are in the upper case, but 
at least those in bcsstk14.mtx are all in the lower case.

Then, the following modifications should work;

/********************* MM_typecode query fucntions ***************************/

#define mm_is_matrix(typecode)  ((typecode)[0]=='M' || (typecode)[0]=='m')

#define mm_is_sparse(typecode)  ((typecode)[1]=='C' || (typecode)[1]=='c')
#define mm_is_coordinate(typecode)((typecode)[1]=='C' || (typecode)[1]=='c')
#define mm_is_dense(typecode)   ((typecode)[1]=='A' || (typecode)[1]=='a')
#define mm_is_array(typecode)   ((typecode)[1]=='A' || (typecode)[1]=='a')

#define mm_is_complex(typecode) ((typecode)[2]=='C' || (typecode)[2]=='c')
#define mm_is_real(typecode)    ((typecode)[2]=='R' || (typecode)[2]=='r')
#define mm_is_pattern(typecode) ((typecode)[2]=='P' || (typecode)[2]=='p')
#define mm_is_integer(typecode) ((typecode)[2]=='I' || (typecode)[2]=='i')

#define mm_is_symmetric(typecode)((typecode)[3]=='S' || (typecode)[3]=='s')
#define mm_is_general(typecode) ((typecode)[3]=='G' || (typecode)[3]=='g')
#define mm_is_skew(typecode)    ((typecode)[3]=='K' || (typecode)[3]=='k')
#define mm_is_hermitian(typecode)((typecode)[3]=='H' || (typecode)[3]=='H')


2020年3月16日月曜日

Q# + C# on Ubuntu 18.04

職場の計算機が使えないので、Q#勉強用の環境をLinuxに構築。
VS Codeはインストールできているとして、C#の環境は以下で簡単に構築可能。

https://docs.microsoft.com/ja-jp/dotnet/core/install/linux-package-manager-ubuntu-1804

matplotlib pcolormeshで、描画領域外でも白く塗りつぶしてしまう問題

Yin-Yang  格子の計算結果をmatplotlibで描画しているのだけれど、
Python3ではデータのない領域でも塗りつぶしてしまうようになったようで、
Yangを描画させると先に出力させていたYinの画像が塗りつぶされてしまう。
下記のURLを参考にして、データが0.0のところは透明にすることで回避できた。

領域外だからゼロじゃなくてNaNとかではないかと思うけれど、深くは気にしない。

https://teratail.com/questions/95800

2020年3月13日金曜日

職場閉鎖

コロナウイルスの関係で、職場が閉鎖になった。
(3/16 - 4/3の三週間)

# 追記
5月18日から戻り始める人がでたけれど、プログラマーである私はリモートでも問題ないという話になり、6月終わり頃になりそう。

2020年3月9日月曜日

ABC 158 C

S = input().split()
[A,B] = [int(i) for i in S]

Alow = A*100//8
Ahi  = (A+1)*100//8

Blow = B*100//10
Bhi  = (B+1)*100//10

#print(Alow,Ahi,Blow,Bhi)

Aran = [i for i in range(Alow,Ahi+1) if int(i*0.08) == A]
Bran = [i for i in range(Blow,Bhi+1) if int(i*0.10) == B]


resRan = sorted(list(set(Aran) & set(Bran)))
#print(resRan)
if len(resRan) !=0:
  print(resRan[0])
else:
  print(-1)
S = input().split()
[A,B] = [int(i) for i in S]

Alow = A*100//8
Ahi  = (A+1)*100//8

Blow = B*100//10
Bhi  = (B+1)*100//10

#print(Alow,Ahi,Blow,Bhi)

Aran = [i for i in range(Alow,Ahi+1) if int(i*0.08) == A]
Bran = [i for i in range(Blow,Bhi+1) if int(i*0.10) == B]


resRan = sorted(list(set(Aran) & set(Bran)))
#print(resRan)
if len(resRan) !=0:
  print(resRan[0])
else:
  print(-1)
うーん。焦ってるとこれぐらいのことも思いつかないもんだなぁ。

S = input().split()
[A,B] = [int(i) for i in S]

Alow = A*100//8
Ahi  = (A+1)*100//8

Blow = B*100//10
Bhi  = (B+1)*100//10

Aran = [i for i in range(Alow,Ahi+1) if int(i*0.08) == A]
Bran = [i for i in range(Blow,Bhi+1) if int(i*0.10) == B]


resRan = sorted(list(set(Aran) & set(Bran)))
if len(resRan) !=0:
  print(resRan[0])
else:
  print(-1)

2020年3月4日水曜日

Atcoder ABC157 E

下記コード、pypyだと通るけど、python3だとTLEする。

https://atcoder.jp/contests/abc157/submissions/10530007
from collections import defaultdict
import bisect
alphabet="abcdefghijklmnopqrstuvwxyz"
bS = int(input())
S= input()
nQ = int(input())
S = [i for i in S]
query = []
for i in range(nQ):
  query.append(input().split())
locs =defaultdict(list)
for i,char in enumerate(S):
    locs[char].append(i)
   
def countChars(iter,ss,ee):
  nChar = 0
  for i in alphabet:
    if len(locs[i]) == 0:
      pass
    else:
      sptr = bisect.bisect_right(locs[i],ss)
      eptr = bisect.bisect_left(locs[i],ee)
      if sptr == eptr:
        if sptr < 1 or sptr > len(locs[i]):
          continue
        else:
          if locs[i][sptr-1] == ss:
            nChar+=1
      else:
        nChar += 1
  return nChar
   
 
res = []
for iter,iQ in enumerate(query):
  if int(iQ[0]) == 2:
    res.append(str( countChars(iter,int(iQ[1])-1,int(iQ[2])) ))
  if int(iQ[0]) == 1:
    location = int(iQ[1])-1
    curChar  = S[location]
    if curChar != iQ[2]:
      locs[curChar].remove(location) #remove from old
      bisect.insort(locs[iQ[2]],location)
      S[location] = iQ[2]
     
print(" ".join(res))