allcoding1
27.7K subscribers
2.2K photos
2 videos
74 files
851 links
Download Telegram
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll solve(ll n)
{


ll position = 1;
ll m = 1;

while (!(n & m)) {


m = m << 1;
position++;
}
return position;
}
int main() {
// your code goes here
ll n,p;
cin>>n;
vector<int> ans(n);
for(int i=0;i<n;i++)
{
cin>>p;

ans[i] = solve(p+1);

}
for(int i=0;i<n;i++)
cout<<ans[i]<<"\n";
return 0;
}

C++

Telegram:- @allcoding1
👍22
#include <bits/stdc++.h>
#define ll long long

using namespace std;

ll solve(ll k, ll s) {
    auto comb = [](ll n) {
        return n * (n - 1) / 2;
    };

    if (k > 3 * s) return 0;

    ll ans = comb(k + 2);

    if (k > s) ans -= 3 * comb(k - s + 1);
    if (k - 2 >= 2 * s) ans += 3 * comb(k - 2 * s);

    return ans;
}

int main() {
    ll n, s;
    cin >> n >> s;
    cout << solve(s,n) << endl;
    return 0;
}

Distribute Car Toy
Service Now

Telegram:- @allcoding1
👍7
allcoding1
Photo
#include <iostream>
#include <sql.h>
#include <sqlext.h>

#define MAX_QUERY_LEN 1000

int main() {
// Declare variables for ODBC connection
SQLHENV henv;
SQLHDBC hdbc;
SQLHSTMT hstmt;
SQLRETURN retcode;

// Allocate environment handle
retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &amp;henv);

// Set the ODBC version to use
retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, 0);

// Allocate connection handle
retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &amp;hdbc);

// Connect to the data source
retcode = SQLConnect(hdbc, (SQLCHAR*)"your_datasource", SQL_NTS, (SQLCHAR*)"username", SQL_NTS, (SQLCHAR*)"password", SQL_NTS);

// Allocate statement handle
retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &amp;hstmt);

// Prepare the SQL query
char query[MAX_QUERY_LEN] = "SELECT DATE_FORMAT(date_column, '%Y-%m') AS month_year, source, COUNT(*) AS total_number FROM your_table WHERE YEAR(date_column) = '2022' AND (source = 'Jobs' OR source = 'Freelancers') GROUP BY month_year, source ORDER BY month_year ASC, source ASC";

// Execute the SQL query
retcode = SQLExecDirect(hstmt, (SQLCHAR*)query, SQL_NTS);

// Fetch and process the results
while (SQLFetch(hstmt) == SQL_SUCCESS) {
// Process the retrieved data here
}

// Free the handles
SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
SQLDisconnect(hdbc);
SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
SQLFreeHandle(SQL_HANDLE_ENV, henv);

return 0;
}
Please note that the above code provides a basic framework for executing SQL queries in C++. You will need to replace your_datasource, username, password, your_table, and date_column with your actual database connection details, table name, and column name.

Telegram:- @allcoding1
👍4
allcoding1
Photo
#define vv(a) vector<vector<int>>(a)
int solve(int n, int m, vector<vector<int>> &a)
{
vv(right)(n, vector<int>(m, 0));
vv(down)(n, vector<int>(m, 0));
vv(left)(n, vector<int>(m, 0));

for (int i = 0; i < n; i++)
{
int cnt = 0;
for (int j = m - 1; j >= 0; j--)
{
right[i][j] = cnt;
if (a[i][j] == 1)
cnt++;
}
}

for (int i = 0; i < n; i++)
{
int cnt = 0;
for (int j = 0; j < m; j++)
{
left[i][j] = cnt;
if (a[i][j] == 1)
cnt++;
}
}

for (int j = 0; j < m; j++)
{
int cnt = 0;
for (int i = n - 1; i >= 0; i--)
{
down[i][j] = cnt;
if (a[i][j] == 1)
cnt++;
}
}

int ans = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (a[i][j] == 1)
{
ans += (right[i][j] * down[i][j]);
ans += (left[i][j] * down[i][j]);
}
}
}
return ans;
}
C++

Telegram:- @allcoding1
2👍2😁2
#include<bits/stdc++.h>
#define ll long long
using namespace std;

ll solve(vector<int>a)
{
   set<int>s(a.begin(),a.end());
   ll mex=0;
    while (s.count(mex)) mex++;
   ll ans=distance(s.lower_bound(mex),s.end());
   if(ans==a.size()) return -2;
   return ans;
}
int main() {
    int n; cin>>n;
    vector<int>arr(n);
    for(int i=0;i<n;i++) cin>>arr[i];
    cout<<solve(arr);
    return 0;
}

Mex Number

@allcoding1
👍1
#include <bits/stdc++.h>
using namespace std;

#define ll long long

int main() {
    ll n;
    cin >> n;
    vector<ll> v(n);
    for(ll i=0; i<n; i++)
        cin >> v[i];

    sort(v.begin(), v.end());

    ll sum = 0;
    for(ll i=0; i<n; i++) {
        if(sum + v[i] < 0)
            return cout << -1, 0;
        sum += v[i];
    }

    if(sum % 2 == 0)
        cout << -1;
    else
        cout << sum;

    return 0;
}


fortunejob

@allcoding1
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define max_v 25
bool f(double A,double B,double a,double b)
{
    double d=sqrt(a*a+b*b);
    double a1=asin(A/d);
    double a2=asin(b/d)*2.0;
    double h=cos(a1-a2)*d;
    if(B>h)
        return true;
    else
        return false;
}
int main()
{
    int t;
    bool flag;
    cin >> t;
    while(t--)
    {
        double A,B,a,b;
        cin >> A >> B >> a >> b;
        if(A<B)
            swap(A,B);
        if(a<b)
            swap(a,b);
        if(A>a&&B>b)
        {
            flag=true;
        }
        else if(A*B<=a*b||b>=B)
        {
            flag=false;
        }else
        {
            flag=f(A,B,a,b);
        }
        if(flag)
        {
            cout << "Escape is possible." << endl;

        }else
        {
            cout << "Box cannot be dropped." << endl;

        }
    }
    return 0;
}

INFAthon 4.0

Telegram:- @allcoding1
👍3🔥1