Harigami
ログイン
12
anonymous タイトルなし
C++
💩
  • 0
  • 0
anonymous タイトルなし
C++
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
#define rep(i, n) for(int i=0; i<(n); ++i)

int main(){ 
    lint N;
    cin >> N;
    vector<lint> A(N);
    rep( i, N ) cin >> A[i];

    vector<lint> ans(N);
    rep( i, N ) ans[0] = A[i] - ans[0];

    for( int i=1; i<N; ++i ) {
        ans[i] = 2 * A[i-1] - ans[i-1];
    }

    rep( i, N ) cout << ans[i] << endl;
}
  • 0
  • 1
anonymous タイトルなし
C++
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(v)    begin(v), end(v)
#define in        []{lint n; cin>>n; return n;}()

int main(){ cin.tie(0); ios::sync_with_stdio(false);
    lint N = in; // < 10^5
    vector<lint> A(N);
    rep( i, N ) A[i] = in;


    vector<lint> ans(N);
    rep( i, N ) ans[0] = A[i] - ans[0];

    for( int i=1; i<N; ++i ) {
        ans[i] = 2 * A[i-1] - ans[i-1];
    }

    rep( i, N-1 ) cout << ans[i] << " ";
    cout << ans[N-1] << "\n";
}
  • 0
  • 0
anonymous タイトルなし
C++
#include <algorithm> // std::transform
#include <iostream>
#include <string>
#include <vector>

// 適当な文字列処理(とりあえず大文字にして返す)
std::string something(const std::string& s)
{
  std::string result;

  for (std::string::const_iterator iter {s.begin()}; iter != s.end(); ++iter)
  {
    result.push_back(std::toupper(*iter));
  }

  return result;
}

int main(void)
{
  std::vector<std::string> VNames = {"hoge", "fuga", "piyo"};

  struct SStore
  {
    std::string name;
    int something;
  };

  SStore stores[3];

  int i = 0;
  for (std::vector<std::string>::iterator iter = VNames.begin(); iter != VNames.end(); iter++)
  {
    // stores[i].name = *iter; //ここで文字コードの問題が発生したため、データを触りたくなった
    stores[i].name = something(*iter);
    ++i;
  }

  // std::cout << stores[2].name << std::endl;

  for (int i = 0; i < 3; ++i)
  {
    std::cout << "stores[" << i << "].name == " << stores[i].name << std::endl;
  }

  return 0;
}

  • 0
  • 1
anonymous タイトルなし
C++
#include <iostream>
#include <vector>
#include <string>

int main (void){
  std::vector<std::string> VNames = {"hoge", "fuga", "piyo"};

  struct SStore  {
    std::string name;
    int something;
  };

  SStore stores[3];
  int i = 0;
  for (std::vector<std::string>::iterator iter = VNames.begin(); iter != VNames.end(); iter++  ){
    stores[i].name = *iter;//ここで文字コードの問題が発生したため、データを触りたくなった
  }

  std::cout << stores[2].name << std::endl;
  
  return 0;
}
  • 0
  • 0
anonymous タイトルなし
C++
#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
#include <math.h>
#include <string.h>
#include"Frog.h"

GLfloat red_f[] = { 1.0, 0.0, 0.0, 1.0 };
GLfloat green_f[] = { 0.0, 1.0, 0.0, 1.0 };
GLfloat white_f[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat black_f[] = { .1, .1, .1, 1.0 };


GLfloat vertexes[8][3] =
{
	{ -1.0, 0.5, 0.5 },
{ -1.0, -0.5, 0.5 },
{ 1.0, -0.5, 0.5 },
{ 1.0, 0.5, 0.5 },
{ -1.0, 0.5, -0.5 },
{ -1.0, -0.5, -0.5 },
{ 1.0, -0.5, -0.5 },
{ 1.0, 0.5, -0.5 }
};


void drawCube() {

	glMaterialfv(GL_FRONT, GL_DIFFUSE, green_f);

	glNormal3f(0, 1, 0);
	glBegin(GL_QUADS);
	glVertex3fv(vertexes[0]);
	glVertex3fv(vertexes[3]);
	glVertex3fv(vertexes[7]);
	glVertex3fv(vertexes[4]);
	glEnd();

	glNormal3f(0, -1, 0);
	glBegin(GL_QUADS);
	glVertex3fv(vertexes[5]);
	glVertex3fv(vertexes[6]);
	glVertex3fv(vertexes[2]);
	glVertex3fv(vertexes[1]);
	glEnd();

	glNormal3f(0, 0, 1);
	glBegin(GL_QUADS);
	glVertex3fv(vertexes[0]);
	glVertex3fv(vertexes[1]);
	glVertex3fv(vertexes[2]);
	glVertex3fv(vertexes[3]);
	glEnd();

	glNormal3f(0, 0, -1);
	glBegin(GL_QUADS);
	glVertex3fv(vertexes[4]);
	glVertex3fv(vertexes[7]);
	glVertex3fv(vertexes[6]);
	glVertex3fv(vertexes[5]);
	glEnd();

	glNormal3f(-1, 0, 0);
	glBegin(GL_QUADS);
	glVertex3fv(vertexes[0]);
	glVertex3fv(vertexes[4]);
	glVertex3fv(vertexes[5]);
	glVertex3fv(vertexes[1]);
	glEnd();

	glNormal3f(1, 0, 0);
	glBegin(GL_QUADS);
	glVertex3fv(vertexes[3]);
	glVertex3fv(vertexes[2]);
	glVertex3fv(vertexes[6]);
	glVertex3fv(vertexes[7]);
	glEnd();
}

void drawEye() {
	glPushMatrix();
	glMaterialfv(GL_FRONT, GL_DIFFUSE, white_f);
	glutSolidSphere(0.4, 30, 30);
	glTranslatef(0, 0, -0.2);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, green_f);
	glutSolidSphere(0.5, 30, 30);
	glTranslatef(0, 0, 0.45);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, black_f);
	glutSolidSphere(0.2, 30, 30);
	glPopMatrix();
}

void drawMouth() {
	glPushMatrix();
	glMaterialfv(GL_FRONT, GL_DIFFUSE, red_f);
	glutSolidCube(0.5);
	glPopMatrix();
}

void drawfrog(void)
{
	/*glPushMatrix();
	glRotatef(90, 1, 0, 0);
	glTranslated(0, 0.5, 0);
	glScalef(0.5, 1, 1);*/
	drawCube();
	glTranslatef(0, -0.2, 0.3);
	drawMouth();
	glTranslatef(-0.5, 1.0, -0.1);
	drawEye();
	glTranslatef(1.0, 0, 0);
	drawEye();
	glPopMatrix();
	//glutSwapBuffers();
}
  • 0
  • 1
anonymous タイトルなし
C++
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1234567;
const ll INF = 2*1e18;
const int inf = 1e9+7;
ll dp[500005];
ll h[500005];
ll b[500005];
int N,P;

bool isOK(int index,ll key){
	if(h[index]>=key)return 1;
	else return 0;
}

int bs(ll key){
	int ok = N+1;
	int ng = -1;
	while(abs(ok-ng)>1){
		int mid = (ok+ng)/2;
		if(isOK(mid,key))ok=mid;
		else ng = mid;
	}
	return ok;
}
int main(void){
	cin >> N >> P;
	for(int i=1;i<=N;i++){
		int a;cin>>a;
		h[i]=h[i-1]+a;
	}
	for(int i=1;i<=N;i++)cout << h[i] <<endl;
	dp[0]=1;
	//h[i]の高さはh[i]-h[i-1];で出せる
	//どの区間まで足せるかを考える
	for(int i=0;i<=N;i++){
		int ng = bs(P+h[i]+1);
		printf("%d から %dまで飛べる\n",i,ng-1);
		dp[i+1]+=dp[i];
		dp[ng]-=dp[i];
	}
	for(int i=1;i<=N;i++){
		dp[i]=dp[i-1]+dp[i];
	}
	cout << dp[N] << endl;
}
  • 0
  • 1
anonymous mergeSort
C++
#include<iostream>
#include<vector>
using namespace std;
const int SENTINEL=(1<<29);

void merge(vector<int>&A,int left,int mid,int right){
  int lm=mid-left,mr=right-mid;
  vector<int> L(lm+1),R(mr+1);
  copy(A.begin()+left,A.begin()+left+lm,L.begin());
  copy(A.begin()+mid,A.begin()+mid+mr,R.begin());
  L[lm]=R[mr]=SENTINEL;
  int Ldx=0,Rdx=0;
  for(int i=left;i<right;++i){
    if(L[Ldx]>R[Rdx])A[i]=R[Rdx++];
    else A[i]=L[Ldx++];
  }

}

void mergeSort(vector<int>&A,int left,int right){
  if(left+1<right){
    int mid=(left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}

int main(){

  int n;
  cin>>n;
  vector<int>A(n);
  for(auto&a:A)cin>>a;

  mergeSort(A,0,n);

  for(auto a:A)cout<<a<<" ";
  cout<<endl;

  return 0;
}
  • 0
  • 1
anonymous quickSort
C++
#include<iostream>
#include<vector>

int partion(std::vector<int>&A,int left,int right){
  int x=A[right];
  int i=left-1;
  for(int j=left;j<right;++j){
    if(A[j]<=x){
      i++;
      std::swap(A[i],A[j]);
    }
  }
  std::swap(A[i+1],A[right]);
  return i+1;
}

void quickSort(std::vector<int>&A,int left,int right){
  if(left<right){
    int q=partion(A,left,right);
    quickSort(A,left,q-1);
    quickSort(A,q+1,right);
  }
}

int main(){

  int n;
  std::cin>>n;
  std::vector<int> A(n);
  for(int i=0;i<n;++i)std::cin>>A[i];

  quickSort(A,0,n-1);
  for(int i=0;i<n;++i)std::cout<<A[i]<<" ";
  std::cout<<std::endl;

  return 0;
}
  • 0
  • 1
anonymous template
C++
#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define step(i,s,n,c) for(int i=(s);i<(n);i+=(c))
#define REP(i,s,n) for(int i=(s);i<(n);++i)
#define each(i,vec) for(auto i:vec)
#define cinv(n,vec) VL vec(n);for(auto&v:vec)cin>>v;
#define int long long
#define itn int
#define pb push_back
#define eb emplace_back
#define m_p make_pair
#define m_t make_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a),greater<>())
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) (signed)(a.size())
#define debg(a) cout<<#a<<" "<<a<<endl;
#define debgp(a) cout<<#a<<" "<<a.fi<<" : "<<a.se<<endl
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define callp(a) for(auto [k,v]:a)cout<<k<<":"<<v<<endl
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define out(a) cout<<(a)<<endl
#define ENDL cout<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define fi first
#define se second
#define V vector
#define P pair
#define T tuple
#define PQ priority_queue
#define cont const auto
#define VV(type,name,y,x,a) vector<vector<type>> name = vector<vector<type>>(y,vector<type>(x,a))
typedef long long ll;
typedef double D;
typedef long double LD;
typedef string str;
typedef vector<ll> VL;
typedef pair<ll,ll> PL;
typedef vector<pair<ll,ll>> VP;
typedef tuple<ll,ll,ll> T3;
typedef tuple<ll,ll,ll,ll> T4;
const signed INF = (1LL<<30);
const long long MOD = (1e9+7);
const long long LINF = (1LL<<60);
const long long LMAX = LLONG_MAX;
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(10);
  
  
  
  
  return 0;
}
  • 0
  • 1
あなたもコードを投稿しませんか?
投稿する
12