(3/16 - 4/3の三週間)
# 追記
5月18日から戻り始める人がでたけれど、プログラマーである私はリモートでも問題ないという話になり、6月終わり頃になりそう。
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)
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))
namespace Qrng {
open Microsoft.Quantum.Intrinsic;
operation SampleQuantumRandomNumberGenerator() : Result {
using (q = Qubit()) { // Allocate a qubit.
H(q); // Put the qubit to superposition. It now has a 50% chance of being 0 or 1.
let r = M(q); // Measure the qubit value.
Reset(q);
return r;
}
}
}
using System;に書き換えて terminal から"dotnet run"すると、乱数が出力された
using Microsoft.Quantum.Simulation.Core;
using Microsoft.Quantum.Simulation.Simulators;
using System.Linq;
namespace Qrng
{
class Driver
{
static void Main(string[] args)
{
using (var sim = new QuantumSimulator())
{
// First we initialize all the variables:
var bitString = "0"; // To save the bit string
int max = 50; // The maximum of the range
int size = Convert.ToInt32(Math.Floor(Math.Log(max, 2.0) + 1));
// To calculate the amount of needed bits
int output = max + 1; // Int to store the output
while (output > max) // Loop to generate the number
{
bitString = "0"; // Restart the bit string if fails
bitString = String.Join("", Enumerable.Range(0, size).Select(idx =>
SampleQuantumRandomNumberGenerator.Run(sim).Result == Result.One ? "1" : "0"
)
);
// Generate and concatenate the bits using using the Q# operation
output = Convert.ToInt32(bitString, 2);
// Convert the bit string to an integer
}
// Print the result
Console.WriteLine($"The random number generated is {output}.");
}
}
}
}