pipenv+PyTorch(Ubuntu20.04)の環境構築に苦しんだ話
背景
- PyTorchの勉強しようと思ったので 公式ページを参考にインストール
- (何も考えてないので)pipのところをpipenvにしたらいけるでしょw的なノリでインストールしたらとりあえず入った
- ↓のコマンドでGPU認識するか確認する
pipenv run python -c "import torch; print(torch.cuda.is_available()); print(torch.cuda.get_device_name())"
- ↓の感じのWarningが出て頭を抱える(私はRTX3070を使ってます) github.com
解決策
pipenv installでwhlファイルのURLを指定する。
pipenv install [URL]
URLは以下画像の-f で指定してあります。URLたどると大量のwhlファイルが...!

良きPyTorchライフを✋
AtCoder ABC-164 C - gacha
方針
最初、C++でやってたんですけど入力した途端にセグフォが出てしまったのでやむなしでpython...
入力した文字をリストに突っ込んでいって、そのリスト内に初めて出てきたらカウントアップするのが王道だと思いますが
この方法でやるとTLEになります。(TLEになりました←)
C++だったらmap、pythonだったらsetでやると高速でやってくれるのでこれで対応。
import os
N = input()
S = set()
N = int(N)
count = 0
for i in range(int(N)):
tmp = input()
if (tmp in S) == False:
count += 1
S.add(tmp)
print (count)
AtCoder ABC-164 B - Battle
方針
高橋くん、青木くんという順番で攻撃することに注意。
体力、攻撃力が2人とも同じだったら高橋くんが勝ちになるので条件分岐を先にいれています。
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
#define lli long ling int;
int main()
{
int A, B, C, D;
scanf("%d %d %d %d", &A, &B, &C, &D);
while(1) {
// takahashi atack
C = C - B;
if (C <= 0) {
printf("Yes\n");
break;
}
// aoki atack
A -= D;
if (A <= 0) {
printf("No\n");
break;
}
}
return 0;
}
AtCoder ABC-164 A - Sheep and Wolves
方針
入力した文字について条件分岐するだけ!
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
#define lli long ling int;
int main()
{
int S, W;
scanf("%d %d", &S, &W);
if(W>=S) {
printf("unsafe\n");
return 0;
}
else {
printf("safe\n");
return 0;
}
return 0;
}
AtCoder ABC-161 B - Popular Vote
方針
得票数を合算して総得票数を出します。
そのあと、総得票数の1/4Mについて判定するんですけど割り算の挙動が怖かったので掛け算に置き換えました。
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
#define lli long ling int;
int main()
{
int N, M, sum=0;
scanf("%d %d", &N, &M);
int A[N];
for (int i=0; i < N; i++) {
scanf("%d", &A[i]);
sum += A[i];
}
int count = 0;
for (int i = 0; i < N; i++)
{
if (A[i]*4*M >= sum) {
count+=1;
}
}
if (count >= M)
printf("Yes\n");
else
{
printf("No\n");
}
return 0;
}
AtCoder ABC-161 A - ABC Swap
グラブルで古戦場が始まってしまったので今日は1問だけ...(しかもA問題)
方針
変数の入れ替えですね、tmp変数用意して入れ替えます。
(ネットでswap関数コピーしてくるのが手っ取り早い)
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
#define lli long ling int;
int main()
{
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
// a, b swap
int tmp = 0;
tmp = a;
a = b;
b = tmp;
// a, c swap
tmp = a;
a = c;
c = tmp;
cout << a << " " << b << " " << c <<endl;
return 0;
}
AtCoder ABC-162 C - Sum of gcd of Tuples (Easy) /
方針
3つの整数に対してユークリッドの互除法を使いました。
3重ループは時間がかかるので非推奨ですが...
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
#define lli long ling int;
int gcd(int a, int b)
{
int r;
r = a % b;
while(r!=0) {
a = b;
b = r;
r = a % b;
}
return b;
}
int main()
{
long long int K, sum = 0;
scanf("%lld", &K);
for (int i = 1; i <= K; i++) {
for (int j = 1; j <= K; j++) {
for (int k = 1; k <= K; k++) {
// i,j,k gcd
int a, b, c, d, tmp;
a = i;
b = j;
c = k;
if (a < b) {
tmp = a;
a = b;
b = tmp;
}
d = gcd(a, b);
if (c < d) {
tmp = c;
c = d;
d = tmp;
}
int res = gcd(c, d);
sum += res;
}
}
}
printf("%lld\n", sum);
return 0;
}