Initial release
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"cmake.configureOnOpen": false
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
struct axis
|
||||
{
|
||||
int x, y;
|
||||
} a[3];
|
||||
int main()
|
||||
{
|
||||
scanf("(%d,%d),(%d,%d),(%d,%d)", &a[0].x, &a[0].y, &a[1].x, &a[1].y, &a[2].x, &a[2].y);
|
||||
//cin>>'('>>a[0].x>>','>>a[0].y>>"),(">>a[1].x>>','>>a[1].y>>"),(">>a[2].x>>','>>a[2].y>>')';
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
printf("[%d,%d]\n", a[i].x, a[i].y);
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
#include<iostream>
|
||||
#include<cstdio>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("\"This is a C++ program.\"\nc:\\teacher\\navision");
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
#include<iostream>
|
||||
#include<cstdio>
|
||||
#include<iomanip>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
float price=0;
|
||||
int code=0;
|
||||
scanf("%d %f",&code,&price);
|
||||
cout<<setfill('0');
|
||||
cout<<setw(8)<<code<<endl;
|
||||
printf("%.2f",price);
|
||||
//printf("%8d\n%.2f",code,price);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
#include<cstdio>
|
||||
#include<iostream>
|
||||
#include<cstdlib>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
float a=0.3,b=0.5;
|
||||
double c=0.3,d=0.5;
|
||||
cout<<(a==c)<<' '<<(b==d);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
cout << sizeof(short) << endl
|
||||
<< sizeof(int) << endl
|
||||
<< sizeof(long) << endl
|
||||
<< sizeof(long long) << endl
|
||||
<< sizeof(float) << endl
|
||||
<< sizeof(double) << endl
|
||||
<< sizeof(long double) << endl
|
||||
<< sizeof(char) << endl;
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int sHour, sMin, sSec, eHour, eMin, eSec;
|
||||
scanf("%d:%d:%d %d:%d:%d", &sHour, &sMin, &sSec, &eHour, &eMin, &eSec);
|
||||
int sTime = sHour * 3600 + sMin * 60 + sSec, eTime = eHour * 3600 + eMin * 60 + eSec, pTime = eTime - sTime;
|
||||
int pHour, pMin, pSec;
|
||||
pHour = pTime / 3600;
|
||||
pMin = (pTime % 3600) / 60;
|
||||
pSec = pTime % 60;
|
||||
cout << setfill('0');
|
||||
cout << pHour << ':' << setw(2) << pMin << ':' << setw(2) << pSec;
|
||||
//printf("%d:%2d:%2d", pHour, pMin, pSec);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
#include<iostream>
|
||||
#include<cstdio>
|
||||
#include<iomanip>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
double c,f;
|
||||
cin>>f;
|
||||
c=5*(f-32)/9;
|
||||
cout<<fixed<<setprecision(5)<<c<<endl;
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n, x, y;
|
||||
cin >> n >> x >> y;
|
||||
n = n - ceil(1.00 * y / x);
|
||||
if (n < 0)
|
||||
{
|
||||
printf("0");
|
||||
return 0;
|
||||
}
|
||||
cout << n;
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
#include <cstdio>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
struct person
|
||||
{
|
||||
int y, m, d;
|
||||
char s;
|
||||
} p[3];
|
||||
int cmp(person a, person b)
|
||||
{
|
||||
if (a.y > b.y)
|
||||
return 0;
|
||||
if (a.y == b.y && a.m > b.m)
|
||||
return 0;
|
||||
if (a.y == b.y && a.m == b.m && a.d > b.d)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
int t;
|
||||
for (t = 0; t < 3; t++)
|
||||
{
|
||||
p[t].s = 'A' + t;
|
||||
scanf("%d %d %d", &p[t].y, &p[t].m, &p[t].d);
|
||||
}
|
||||
sort(p, p + 3, cmp);
|
||||
printf("%c%c%c", p[0].s, p[1].s, p[2].s);
|
||||
return 0;
|
||||
}
|
After Width: | Height: | Size: 42 KiB |
|
@ -0,0 +1,33 @@
|
|||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n, rn, score = 0;
|
||||
char type;
|
||||
scanf("%d\n", &n);
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
scanf("%c\n", &type);
|
||||
if (type == 'r')
|
||||
{
|
||||
scanf("%d\n", &rn);
|
||||
score += rn;
|
||||
}
|
||||
if (type == 'y')
|
||||
score += 2;
|
||||
if (type == 'g')
|
||||
score += 3;
|
||||
if (type == 'c')
|
||||
score += 4;
|
||||
if (type == 'b')
|
||||
score += 5;
|
||||
if (type == 'p')
|
||||
score += 6;
|
||||
if (type == 'B')
|
||||
score += 7;
|
||||
}
|
||||
printf("%d", score);
|
||||
return 0;
|
||||
}
|
After Width: | Height: | Size: 112 KiB |
|
@ -0,0 +1,26 @@
|
|||
#include<cstdio>
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n,t,num=0,other=0,cap=0,low=0,sum=0;
|
||||
char c;
|
||||
scanf("%d\n",&n);
|
||||
for(t=0;t<n;t++)
|
||||
{
|
||||
if(t!=n-1)scanf("%c\n",&c);
|
||||
else scanf("%c",&c);
|
||||
if('0'<=c&&c<='9')
|
||||
{
|
||||
num++;
|
||||
sum+=c-'0';
|
||||
}
|
||||
else if('a'<=c&&c<='z') low++;
|
||||
else if('A'<=c&&c<='Z') cap++;
|
||||
else other++;
|
||||
}
|
||||
printf("%d %d %d %d",cap,low,num,other);
|
||||
if(sum)printf("\n%d",sum);
|
||||
return 0;
|
||||
}
|
After Width: | Height: | Size: 95 KiB |
|
@ -0,0 +1,21 @@
|
|||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
scanf("%d", &n);
|
||||
if (n < 60)
|
||||
printf("E");
|
||||
else if (n < 70)
|
||||
printf("D");
|
||||
else if (n < 80)
|
||||
printf("C");
|
||||
else if (n < 90)
|
||||
printf("B");
|
||||
else
|
||||
printf("A");
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
After Width: | Height: | Size: 56 KiB |
|
@ -0,0 +1,21 @@
|
|||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int y, m;
|
||||
bool r = false;
|
||||
scanf("%d%d", &y, &m);
|
||||
if (y % 400 == 0 || (y % 100 != 0 && y % 4 == 0))
|
||||
r = true;
|
||||
if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)
|
||||
printf("31");
|
||||
if (m == 4 || m == 6 || m == 9 || m == 11)
|
||||
printf("30");
|
||||
if (m == 2 && r)
|
||||
printf("29");
|
||||
if (m == 2 && !r)
|
||||
printf("28");
|
||||
return 0;
|
||||
}
|
After Width: | Height: | Size: 35 KiB |
|
@ -0,0 +1,27 @@
|
|||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
scanf("%d", &n);
|
||||
bool d3 = !(n % 3), d5 = !(n % 5), d7 = !(n % 7);
|
||||
if (d3 && d5 && d7)
|
||||
printf("It\'s divisible by 3,5,7");
|
||||
else if (!d3 && d5 && d7)
|
||||
printf("It\'s divisible by 5,7");
|
||||
else if (d3 && !d5 && d7)
|
||||
printf("It\'s divisible by 3,7");
|
||||
else if (d3 && d5 && !d7)
|
||||
printf("It\'s divisible by 3,5");
|
||||
else if (!d3 && !d5 && d7)
|
||||
printf("It\'s divisible by 7");
|
||||
else if (!d3 && d5 && !d7)
|
||||
printf("It\'s divisible by 5");
|
||||
else if (d3 && !d5 && !d7)
|
||||
printf("It\'s divisible by 3");
|
||||
else if (!d3 && !d5 && !d7)
|
||||
printf("null");
|
||||
return 0;
|
||||
}
|
After Width: | Height: | Size: 68 KiB |
|
@ -0,0 +1,15 @@
|
|||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int salary, dist;
|
||||
char vacation;
|
||||
scanf("%d %c %d", &salary, &vacation, &dist);
|
||||
if ((salary >= 5000) + (vacation == 'y') + (dist <= 2000) >= 2)
|
||||
printf("Accept");
|
||||
else
|
||||
printf("Refuse");
|
||||
return 0;
|
||||
}
|
After Width: | Height: | Size: 70 KiB |
|
@ -0,0 +1,45 @@
|
|||
#include <iostream>
|
||||
#include <cstdio>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
char n;
|
||||
scanf("%c", &n);
|
||||
switch (n)
|
||||
{
|
||||
case '0':
|
||||
printf("Zero");
|
||||
break;
|
||||
case '1':
|
||||
printf("One");
|
||||
break;
|
||||
case '2':
|
||||
printf("Two");
|
||||
break;
|
||||
case '3':
|
||||
printf("Three");
|
||||
break;
|
||||
case '4':
|
||||
printf("Four");
|
||||
break;
|
||||
case '5':
|
||||
printf("Five");
|
||||
break;
|
||||
case '6':
|
||||
printf("Six");
|
||||
break;
|
||||
case '7':
|
||||
printf("Seven");
|
||||
break;
|
||||
case '8':
|
||||
printf("Eight");
|
||||
break;
|
||||
case '9':
|
||||
printf("Nine");
|
||||
break;
|
||||
default:
|
||||
printf("Other");
|
||||
}
|
||||
return 0;
|
||||
}
|
After Width: | Height: | Size: 33 KiB |
|
@ -0,0 +1,25 @@
|
|||
#include <cstdio>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
int cmp(int a, int b)
|
||||
{
|
||||
if (a < b)
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
int a[4];
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
scanf("%d", &a[i]);
|
||||
}
|
||||
sort(a, a + 4, cmp);
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
printf("%d ", a[i]);
|
||||
}
|
||||
return 0;
|
||||
}
|
After Width: | Height: | Size: 33 KiB |
|
@ -0,0 +1,13 @@
|
|||
#include<cstdio>
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
double x;
|
||||
scanf("%lf",&x);
|
||||
if(x<=-1)printf("%.6lf",x-1);
|
||||
else if(x<=2)printf("%.6lf",x*2);
|
||||
else printf("%.6lf",(x*x+x*2));
|
||||
return 0;
|
||||
}
|
After Width: | Height: | Size: 42 KiB |
|
@ -0,0 +1,50 @@
|
|||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int income, d, a;
|
||||
scanf("%d %d", &income, &d);
|
||||
income -= d + 5000;
|
||||
if (income < 0)
|
||||
{
|
||||
printf("0");
|
||||
}
|
||||
if (0 < income && income <= 3000)
|
||||
{
|
||||
a = 0.03 * income;
|
||||
printf("%d", a);
|
||||
}
|
||||
if (3000 < income && income <= 12000)
|
||||
{
|
||||
a = 0.1 * income - 210;
|
||||
printf("%d", a);
|
||||
}
|
||||
if (12000 < income && income <= 25000)
|
||||
{
|
||||
a = 0.2 * income - 1410;
|
||||
printf("%d", a);
|
||||
}
|
||||
if (25000 < income && income <= 35000)
|
||||
{
|
||||
a = 0.25 * income - 2660;
|
||||
printf("%d", a);
|
||||
}
|
||||
if (income > 35000 && income <= 55000)
|
||||
{
|
||||
a = 0.3 * income - 4410;
|
||||
printf("%d", a);
|
||||
}
|
||||
if (55000 < income && income <= 80000)
|
||||
{
|
||||
a = 0.35 * income - 7160;
|
||||
printf("%d", a);
|
||||
}
|
||||
if (income > 80000)
|
||||
{
|
||||
a = 0.45 * income - 15160;
|
||||
printf("%d", a);
|
||||
}
|
||||
return 0;
|
||||
}
|
After Width: | Height: | Size: 148 KiB |
|
@ -0,0 +1,16 @@
|
|||
#include<cstdio>
|
||||
#include<iostream>
|
||||
#include<algorithm>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
long long int num[4],a,b,c;
|
||||
scanf("%lld %lld %lld %lld",&num[0],&num[1],&num[2],&num[3]);
|
||||
sort(num,num+4);
|
||||
a=num[3]-num[2];
|
||||
b=num[3]-num[1];
|
||||
c=num[3]-num[0];
|
||||
printf("%lld %lld %lld",a,b,c);
|
||||
return 0;
|
||||
}
|
After Width: | Height: | Size: 65 KiB |
|
@ -0,0 +1,38 @@
|
|||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int w, d, a;
|
||||
scanf("%d%d", &w, &d);
|
||||
w = w * d;
|
||||
if (d < 250)
|
||||
printf("%d", w);
|
||||
if (d >= 250 && d < 500)
|
||||
{
|
||||
a = w * 0.98;
|
||||
printf("%d", a);
|
||||
}
|
||||
if (d >= 500 && d < 1000)
|
||||
{
|
||||
a = w * 0.95;
|
||||
printf("%d", a);
|
||||
}
|
||||
if (d >= 1000 && d < 2000)
|
||||
{
|
||||
a = w * 0.92;
|
||||
printf("%d", a);
|
||||
}
|
||||
if (d >= 2000 && d < 3000)
|
||||
{
|
||||
a = w * 0.9;
|
||||
printf("%d", a);
|
||||
}
|
||||
if (d >= 3000)
|
||||
{
|
||||
a = w * 0.85;
|
||||
printf("%d", a);
|
||||
}
|
||||
return 0;
|
||||
}
|
After Width: | Height: | Size: 74 KiB |
|
@ -0,0 +1,19 @@
|
|||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
double tBike, tWalk;
|
||||
int dist;
|
||||
scanf("%d", &dist);
|
||||
tBike = 27 + 23 + dist / 3.0;
|
||||
tWalk = dist / 1.2;
|
||||
if (tBike > tWalk)
|
||||
printf("Walk");
|
||||
if (tBike == tWalk)
|
||||
printf("All");
|
||||
if (tBike < tWalk)
|
||||
printf("Bike");
|
||||
return 0;
|
||||
}
|
After Width: | Height: | Size: 121 KiB |
|
@ -0,0 +1,38 @@
|
|||
#include<iostream>
|
||||
#include<cstdio>
|
||||
#include<algorithm>
|
||||
#include<cmath>
|
||||
using namespace std;
|
||||
struct work
|
||||
{
|
||||
int num,score;
|
||||
}w[3];
|
||||
int swp(work a,work b);
|
||||
int rnd(double number)
|
||||
{
|
||||
return (number > 0.0) ? (number + 0.5) : (number - 0.5);
|
||||
}
|
||||
int main()
|
||||
{
|
||||
int salary, dist;
|
||||
char vacation;
|
||||
double x;
|
||||
for(int i=0;i<3;i++)
|
||||
{
|
||||
scanf("%d %c %d", &salary, &vacation, &dist);
|
||||
w[i].num=i;
|
||||
w[i].score+=rnd(1.0*salary/5000)*100;
|
||||
x=1.0*salary/5000;
|
||||
if(vacation=='y')w[i].score+=20;
|
||||
if(dist<=4000)w[i].score+=100;
|
||||
if(2000<=dist&&dist<=4000)w[i].score-=ceil((dist-2000)*1.0/200)*10;
|
||||
}
|
||||
sort(w,w+3,swp);
|
||||
printf("%c",w[0].num+'A');
|
||||
return 0;
|
||||
}
|
||||
int swp(work a,work b)
|
||||
{
|
||||
if(a.score<=b.score)return false;
|
||||
else return true;
|
||||
}
|
After Width: | Height: | Size: 106 KiB |
|
@ -0,0 +1,32 @@
|
|||
#include<cstdio>
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
char a,b,c[10];
|
||||
int i,j;
|
||||
cin>>a>>b;
|
||||
for(i=0;i<10;i++)
|
||||
{
|
||||
cin>>c[i];
|
||||
}
|
||||
for(i=0;i<10;i+=2)//判断点数
|
||||
{
|
||||
if(c[i]==a)
|
||||
{
|
||||
cout<<"YES";
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
for(i=1;i<10;i+=2)//判断花色
|
||||
{
|
||||
if(c[i]==b)
|
||||
{
|
||||
cout<<"YES";
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
cout<<"NO";
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
//21 小熊与糖果
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int t, a, b, i, j;
|
||||
scanf("%d", &t);
|
||||
for (i = 0; i < t; i++)
|
||||
{
|
||||
scanf("%d%d", &a, &b);
|
||||
for (j = 1; true; j++)
|
||||
{
|
||||
if (j % 2 == 1)
|
||||
{
|
||||
a -= j;
|
||||
if (a < 0)
|
||||
{
|
||||
printf("Bob\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
b -= j;
|
||||
if (b < 0)
|
||||
{
|
||||
printf("Limak\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
//金币 NOIp PJ 2015 P1
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n = 0, i, k, last = 0, sum = 0;
|
||||
scanf("%d", &k);
|
||||
for (i = 1; i <= k; i++)
|
||||
{
|
||||
if (last == 0)
|
||||
{
|
||||
n++;
|
||||
last = n;
|
||||
}
|
||||
last--;
|
||||
sum += n;
|
||||
}
|
||||
printf("%d", sum);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
//牛友(打表器) USACO 2011?
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
int ysh(int x);
|
||||
int main()
|
||||
{
|
||||
int ny[15] = {220, 284, 1184, 1210, 2620, 2924, 5020, 5564, 6232, 6368, 10744, 10856, 12285, 14595, 17296};
|
||||
int ny2[15] = {284, 220, 1210, 1184, 2924, 2620, 5564, 5020, 6368, 6232, 10856, 10744, 14595, 12285, 18416};
|
||||
int s, i;
|
||||
scanf("%d", &s);
|
||||
for (i = 0; i < 15; i++)
|
||||
{
|
||||
if (ny[i] >= s)
|
||||
{
|
||||
printf("%d %d", ny[i], ny2[i]);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
//牛友(打表器) USACO 2011?
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
int ysh(int x);
|
||||
int main()
|
||||
{
|
||||
int i, j, m, n;
|
||||
for (i = 6; i <= 18000; i++)
|
||||
{
|
||||
m = ysh(i);
|
||||
n = ysh(m);
|
||||
if (n == i && i != m)
|
||||
{
|
||||
printf("%d,", i);
|
||||
//To output ny2 list, use:
|
||||
//printf("%d,",m);
|
||||
}
|
||||
}
|
||||
}
|
||||
int ysh(int x)
|
||||
{
|
||||
int sum = 0;
|
||||
for (int m = 1; m < x; m++)
|
||||
{
|
||||
if (x % m == 0)
|
||||
{
|
||||
sum += m;
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
//24 汉明距离
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
long long int a, b, i;
|
||||
int a2 = 0, b2 = 0, t, dist = 0;
|
||||
scanf("%lld %lld", &a, &b);
|
||||
for (t = 31; t >= 0; t--)
|
||||
{
|
||||
a2 = 0;
|
||||
b2 = 0;
|
||||
i = pow(2, t);
|
||||
a2 = a / i;
|
||||
a %= i;
|
||||
b2 = b / i;
|
||||
b %= i;
|
||||
if (a2 != b2)
|
||||
{
|
||||
dist++;
|
||||
}
|
||||
}
|
||||
printf("%d", dist);
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
//20 下载文件
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int k, m, n, t, tt, d, i, j, sum, totalMin;
|
||||
scanf("%d", &tt);
|
||||
for (i = 0; i < tt; i++)
|
||||
{
|
||||
totalMin = 0;
|
||||
sum = 0;
|
||||
scanf("%d%d", &n, &k);
|
||||
for (j = 0; j < n; j++)
|
||||
{
|
||||
scanf("%d %d", &t, &d);
|
||||
totalMin += t;
|
||||
if (totalMin <= k)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (totalMin - t <= k && totalMin > k)
|
||||
{
|
||||
sum += (totalMin - k) * d;
|
||||
}
|
||||
if (totalMin - t > k)
|
||||
{
|
||||
sum += t * d;
|
||||
}
|
||||
}
|
||||
printf("%d\n", sum);
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
//16 阿迪玩游戏
|
||||
#include<cstdio>
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int i,x,y,n,m,step,sum=0,period;
|
||||
scanf("%d %d",&n,&m);
|
||||
for(i=0;i<m;i++)
|
||||
{
|
||||
scanf("%d",&step);
|
||||
sum+=step;
|
||||
}
|
||||
period=2*(n-1);
|
||||
sum%=period;
|
||||
if(sum<=n-1)
|
||||
{
|
||||
x=sum+1;
|
||||
printf("%d",x);
|
||||
}
|
||||
else
|
||||
{
|
||||
x=2*n-sum-1;
|
||||
printf("%d",x);
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
//23 大象看朋友
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
using namespace std;
|
||||
int jishu(int x);
|
||||
int main()
|
||||
{
|
||||
int a, x, m, count = 0;
|
||||
scanf("%d%d", &x, &m);
|
||||
x = abs(x);
|
||||
m = m * 2 - 1;
|
||||
while (x != 0)
|
||||
{
|
||||
count++;
|
||||
a = jishu(x);
|
||||
if (a > m)
|
||||
{
|
||||
x -= m;
|
||||
}
|
||||
else
|
||||
{
|
||||
x -= a;
|
||||
}
|
||||
}
|
||||
printf("%d", count);
|
||||
return 0;
|
||||
}
|
||||
int jishu(int x)
|
||||
{
|
||||
if (x % 2 == 0)
|
||||
{
|
||||
return x / 2 * 2 - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return x;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
//19 电梯
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n, req, prevFloor = 0, t, sum = 0;
|
||||
scanf("%d", &n);
|
||||
for (t = 0; t < n; t++)
|
||||
{
|
||||
scanf("%d", &req);
|
||||
sum += 5;
|
||||
if (req > prevFloor)
|
||||
{
|
||||
sum += 6 * (req - prevFloor);
|
||||
}
|
||||
if (req < prevFloor)
|
||||
{
|
||||
sum += 4 * (prevFloor - req);
|
||||
}
|
||||
prevFloor = req;
|
||||
}
|
||||
printf("%d", sum);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
//找12
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
int check(int x);
|
||||
int main()
|
||||
{
|
||||
int i, n;
|
||||
scanf("%d", &n);
|
||||
printf("12");
|
||||
for (i = 13; i <= n; i++)
|
||||
{
|
||||
if (check(i) || i % 12 == 0)
|
||||
{
|
||||
printf(" %d", i);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int check(int x)
|
||||
{
|
||||
int a = 0, b = 0;
|
||||
while (x >= 1)
|
||||
{
|
||||
b = a;
|
||||
a = x % 10;
|
||||
if (a == 1 && b == 2)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
x /= 10;
|
||||
}
|
||||
return false;
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
//找7
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
int check(int x);
|
||||
int main()
|
||||
{
|
||||
int i, n;
|
||||
scanf("%d", &n);
|
||||
printf("7");
|
||||
for (i = 8; i <= n; i++)
|
||||
{
|
||||
if (check(i) || i % 7 == 0)
|
||||
{
|
||||
printf(" %d", i);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int check(int x)
|
||||
{
|
||||
int a, b;
|
||||
while (x >= 1)
|
||||
{
|
||||
a = x % 10;
|
||||
if (a == 7)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
x /= 10;
|
||||
}
|
||||
return false;
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
//青蛙跳
|
||||
#include<cstdio>
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int k,a,b,t;
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
//松雅旅馆的自动门
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int i, n, m, a, d, countdown, x, tmax, open = 0;
|
||||
bool door = false;
|
||||
bool time[100000] = {0};
|
||||
scanf("%d%d%d%d", &n, &m, &a, &d);
|
||||
for (i = 1; i <= n; i++)
|
||||
{
|
||||
time[i * a] = 1;
|
||||
}
|
||||
tmax = n * a;
|
||||
for (i = 0; i < m; i++)
|
||||
{
|
||||
scanf("%d", &x);
|
||||
time[x] = 1;
|
||||
if (x > tmax)
|
||||
{
|
||||
tmax = x;
|
||||
}
|
||||
}
|
||||
for (int i = 1; i <= tmax; i++)
|
||||
{
|
||||
if (door)
|
||||
{
|
||||
if (countdown == 0)
|
||||
door = false;
|
||||
else
|
||||
countdown--;
|
||||
}
|
||||
if (time[i])
|
||||
{
|
||||
if (!door)
|
||||
{
|
||||
countdown = d;
|
||||
open++;
|
||||
door=true;
|
||||
}
|
||||
else
|
||||
{
|
||||
countdown--;
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("%d",open);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
#include<cstdio>
|
||||
#include<iostream>
|
||||
#include<algorithm>
|
||||
using namespace std;
|
||||
int inTime[1000];
|
||||
int main()
|
||||
{
|
||||
int n,m,a,d,i,j,count=0,closeTime=0;
|
||||
bool door=false;
|
||||
scanf("%d %d %d %d",&n,&m,&a,&d);
|
||||
for(i=0;i<m;i++)
|
||||
{
|
||||
scanf("%d",&inTime[i]);
|
||||
}
|
||||
for(j=m;j<m+n;j++)
|
||||
{
|
||||
inTime[j]=(j-m+1)*a;
|
||||
}
|
||||
sort(inTime,inTime+n+m);
|
||||
for(i=0;i<inTime[m+n-1];i++)
|
||||
{
|
||||
if(!door)
|
||||
{
|
||||
door=true;
|
||||
count++;
|
||||
closeTime=inTime[i]+d;
|
||||
}
|
||||
if(inTime[i+1]>closeTime)
|
||||
{
|
||||
door=false;
|
||||
closeTime=inTime[i+1];
|
||||
}
|
||||
}
|
||||
if(inTime[m+n-1]>closeTime)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
printf("%d",count);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
//13 青蛙跳
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
long long int a, b, t, k, i;
|
||||
long long int pos;
|
||||
scanf("%lld", &t);
|
||||
for (i = 0; i < t; i++)
|
||||
{
|
||||
scanf("%lld %lld %lld", &a, &b, &k);
|
||||
if (k % 2 == 0)
|
||||
{
|
||||
pos = (k / 2) * (a - b);
|
||||
printf("%lld\n", pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
pos = floor(k / 2.0) * (a - b) + a;
|
||||
printf("%lld\n", pos);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
//12 懒惰的松雅
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
bool checkluck(int h, int m);
|
||||
int main()
|
||||
{
|
||||
int th, tm, x, count = 0;
|
||||
scanf("%d%d%d", &x, &th, &tm);
|
||||
if (checkluck(th, tm))
|
||||
{
|
||||
printf("0");
|
||||
return 0;
|
||||
}
|
||||
do
|
||||
{
|
||||
count++;
|
||||
if (tm < x && th == 0)
|
||||
{
|
||||
th += 24;
|
||||
}
|
||||
if (tm < x)
|
||||
{
|
||||
th--;
|
||||
tm += 60;
|
||||
}
|
||||
tm -= x;
|
||||
} while (!checkluck(th, tm));
|
||||
printf("%d", count);
|
||||
return 0;
|
||||
}
|
||||
bool checkluck(int h, int m)
|
||||
{
|
||||
int h1, h2, m1, m2;
|
||||
h1 = h / 10;
|
||||
h2 = h % 10;
|
||||
m1 = m / 10;
|
||||
m2 = m % 10;
|
||||
if (h1 == 7 || h2 == 7 || m1 == 7 || m2 == 7)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
//22莫比乌斯函数
|
||||
#include<cstdio>
|
||||
#include<iostream>
|
||||
#include<cmath>
|
||||
using namespace std;
|
||||
int ss(int x);
|
||||
void check(int x,int count,int last);
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
scanf("%d",&n);
|
||||
if(n==1)//特判1
|
||||
{
|
||||
printf("1");
|
||||
return 0;
|
||||
}
|
||||
if(n%4==0||n%9==0)//特判4或9为因子,肯定是存在平方因子
|
||||
{
|
||||
printf("0");
|
||||
return 0;
|
||||
}
|
||||
if(ss(n)==0)//特判素数……有必要么?
|
||||
{
|
||||
printf("-1");
|
||||
return 0;
|
||||
}
|
||||
check(n,0,1);
|
||||
return 0;
|
||||
}
|
||||
void check(int x,int count,int last)
|
||||
{
|
||||
int a=ss(x);
|
||||
if(a==last||last==x)
|
||||
{
|
||||
printf("0");
|
||||
return;
|
||||
}
|
||||
if(a==0)
|
||||
{
|
||||
if(count%2==1)
|
||||
{
|
||||
printf("-1");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("1");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
check(x/a,count+1,a);
|
||||
}
|
||||
return;
|
||||
}
|
||||
int ss(int x)
|
||||
{
|
||||
int y,t=sqrt(x);
|
||||
for(y=2;y<=t;y++)
|
||||
{
|
||||
if(x%y==0)
|
||||
{
|
||||
return y;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
//莫比乌斯函数
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
using namespace std;
|
||||
int ss(int x);
|
||||
int main()
|
||||
{
|
||||
int y, n, count = 0;
|
||||
scanf("%d", &n);
|
||||
if (n == 1) //n=1的特判
|
||||
{
|
||||
printf("1");
|
||||
return 0;
|
||||
}
|
||||
if (ss(n) == 0) //素数的特判
|
||||
{
|
||||
printf("-1");
|
||||
return 0;
|
||||
}
|
||||
while (n > 1)
|
||||
{
|
||||
y = ss(n); //n是否没有其他因子了?
|
||||
if (y == 0)
|
||||
{
|
||||
count++; //剩下的这个n本身也是一个因子
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
n /= y; //除掉y这个因子
|
||||
count++;
|
||||
if (n % y == 0) //n可以被y整除2次,一定有平方因子
|
||||
{
|
||||
printf("0");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count % 2) //奇数个的
|
||||
{
|
||||
printf("-1");
|
||||
}
|
||||
else //偶数个的
|
||||
{
|
||||
printf("1");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int ss(int x)
|
||||
{
|
||||
int y, t = sqrt(x);
|
||||
for (y = 2; y <= t; y++)
|
||||
{
|
||||
if (x % y == 0)
|
||||
{
|
||||
return y;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
//这是一个几位数
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
char num[100];
|
||||
cin >> num;
|
||||
bool if0 = true;
|
||||
int len = strlen(num);
|
||||
printf("%d ", len);
|
||||
for (int i = len - 1; i >= 0; i--)
|
||||
{
|
||||
if (num[i] != '0')
|
||||
if0 = false;
|
||||
if (!if0)
|
||||
printf("%c", num[i]);
|
||||
}
|
||||
if (if0)
|
||||
printf("0"); //第三个点特判
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
//数字游戏
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
int multiply(int x);
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
scanf("%d", &n);
|
||||
printf("%d", n);
|
||||
while (n >= 10)
|
||||
{
|
||||
n = multiply(n);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int multiply(int x)
|
||||
{
|
||||
int digit, sum = 1;
|
||||
while (x >= 1)
|
||||
{
|
||||
digit = x % 10;
|
||||
x /= 10;
|
||||
if (digit)
|
||||
sum *= digit;
|
||||
}
|
||||
printf(" %d", sum);
|
||||
return sum;
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
//10 松雅喜欢玩纸牌
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
struct card
|
||||
{
|
||||
char color, point;
|
||||
} pCard[5], hCard;
|
||||
int main()
|
||||
{
|
||||
scanf("%c%c\n", &hCard.point, &hCard.color);
|
||||
int i;
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
scanf("%c%c\n", &pCard[i].point, &pCard[i].color);
|
||||
if (pCard[i].point == hCard.point || pCard[i].color == hCard.color)
|
||||
{
|
||||
printf("YES");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
printf("NO");
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
//17 桃子问题
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n, i;
|
||||
scanf("%d", &n);
|
||||
long long int peach = 1;
|
||||
for (i = 1; i < n; i++)
|
||||
{
|
||||
peach = (peach + 1) * 2;
|
||||
}
|
||||
printf("%lld", peach);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
//18 完美数
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
int ysh(int x);
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
scanf("%d", &n);
|
||||
if (ysh(n) == n)
|
||||
printf("true");
|
||||
else
|
||||
printf("false");
|
||||
return 0;
|
||||
}
|
||||
int ysh(int x)
|
||||
{
|
||||
int sum = 0;
|
||||
for (int m = 1; m < x; m++)
|
||||
{
|
||||
if (x % m == 0)
|
||||
{
|
||||
sum += m;
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
//1 除法的精确计算
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int a, b, pos, n, t;
|
||||
scanf("%d %d %d", &a, &b, &n);
|
||||
t = a / b;
|
||||
a = a % b * 10;
|
||||
printf("%d.", t);
|
||||
for (pos = 0; pos < n; pos++)
|
||||
{
|
||||
t = a / b;
|
||||
a = a % b * 10;
|
||||
printf("%d", t);
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
//11 整数反转
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
long long int n, m = 0;
|
||||
int t, i;
|
||||
bool pos = true, if0 = true;
|
||||
;
|
||||
scanf("%lld", &n);
|
||||
if (n < 0)
|
||||
{
|
||||
pos = false;
|
||||
n *= -1;
|
||||
}
|
||||
if (n == 0)
|
||||
{
|
||||
printf("0");
|
||||
return 0;
|
||||
}
|
||||
while (n >= 1)
|
||||
{
|
||||
t = n % 10;
|
||||
n /= 10;
|
||||
if (t == 0 && if0)
|
||||
continue;
|
||||
if (t != 0 && if0)
|
||||
if0 = false;
|
||||
m += t;
|
||||
m *= 10;
|
||||
}
|
||||
if (!pos)
|
||||
m *= -1;
|
||||
m /= 10;
|
||||
if (m < -2147483648 || m > 2147483647)
|
||||
{
|
||||
printf("0");
|
||||
return 0;
|
||||
}
|
||||
printf("%lld", m);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
//8 求sinx的近似值
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
using namespace std;
|
||||
const double pi = 3.1415926535;
|
||||
long long int fac(int x)
|
||||
{
|
||||
long long int f[16]={0,1,2,6,24,120,720,5040,40320,362880,3628800,39916800,479001600,6227020800,87178291200};
|
||||
if(x<16)return f[x];
|
||||
else return x*fac(x-1);
|
||||
}
|
||||
int main()
|
||||
{
|
||||
double x, t = 10000.0, sum = 0;
|
||||
int i;
|
||||
int multiply = 1;
|
||||
scanf("%lf", &x);
|
||||
if (x < 0)
|
||||
{
|
||||
multiply *= -1;
|
||||
x *= -1;
|
||||
}
|
||||
while (x >= 2 * pi)
|
||||
{
|
||||
x -= 2 * pi;
|
||||
}
|
||||
if (x > pi)
|
||||
{
|
||||
multiply *= -1;
|
||||
x -= pi;
|
||||
}
|
||||
sum+=x;
|
||||
for (i = 1; fabs(t) >= 0.0000007; i++)
|
||||
{
|
||||
t = pow(x, 2 * i + 1) * 1.0 / fac(2 * i + 1);
|
||||
if (i % 2 == 1)
|
||||
t *= -1;
|
||||
sum += t;
|
||||
}
|
||||
sum*=multiply;
|
||||
printf("%.6f", sum);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
整型下,到11!左右就会越界。
|
||||
|
||||
不要单独计算。存储上一项,将其乘x^2,再除2n*(2n+1)。
|
|
@ -0,0 +1,29 @@
|
|||
//8.求sin(x)的近似值 用库函数混过去
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
using namespace std;
|
||||
const double pi = 3.1415926535;
|
||||
int main()
|
||||
{
|
||||
int i, t, multiply = 1;
|
||||
double x, y;
|
||||
scanf("%lf", &x);
|
||||
if (x < 0)
|
||||
{
|
||||
x *= -1;
|
||||
multiply *= -1;
|
||||
}
|
||||
while (x >= 2 * pi)
|
||||
{
|
||||
x -= 2 * pi;
|
||||
}
|
||||
if (x > pi)
|
||||
{
|
||||
x -= pi;
|
||||
multiply *= -1;
|
||||
}
|
||||
y = sin(x) * multiply;
|
||||
printf("%.6f", y);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
//9 今夕何夕
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
int run(int year);
|
||||
bool check(int year);
|
||||
bool hRun(int year);
|
||||
int main()
|
||||
{
|
||||
int a, t, i, yr, mon, day, x; //t是数据组数,yr mon day是日期
|
||||
scanf("%d", &t);
|
||||
for (i = 0; i < t; i++)
|
||||
{
|
||||
scanf("%d-%d-%d", &yr, &mon, &day);
|
||||
a = run(yr);
|
||||
if (a == 0 && mon == 2 && day == 29) //跨越百年,不一定都是闰年!28年里,不一定7个闰年!
|
||||
{
|
||||
if (hRun(yr)) //跨越百年且百年不是闰年的情况
|
||||
{
|
||||
x = yr + 12;
|
||||
printf("%d\n", x);
|
||||
}
|
||||
else
|
||||
{
|
||||
x = yr + 28;
|
||||
printf("%d\n", x);
|
||||
}
|
||||
}
|
||||
else if ((a == 0 && mon <= 2) || (a == 3 && mon >= 3)) //闰年1-2月/闰年+3 3-12月,以此类推
|
||||
{
|
||||
x = yr + 5;
|
||||
printf("%d\n", x);
|
||||
}
|
||||
else if ((a == 0 && mon >= 3) || (a == 1) || (a == 2 && mon <= 2))
|
||||
{
|
||||
x = yr + 6;
|
||||
printf("%d\n", x);
|
||||
}
|
||||
else if ((a == 2 && mon >= 3) || (a == 3 && mon <= 2))
|
||||
{
|
||||
x = yr + 11;
|
||||
printf("%d\n", x);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int run(int year) //这一年离上一个闰年多久了?
|
||||
{
|
||||
if (check(year))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (check(year - 1))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (check(year - 2))
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
if (check(year - 3))
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
bool check(int year)
|
||||
{
|
||||
if (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
bool hRun(int year)
|
||||
{
|
||||
int hYear = (year + 28) / 100 * 100;
|
||||
if (hYear > year && !check(hYear))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
10
|
||||
1917-3-8 THU
|
||||
2067-1-31 MON
|
||||
2075-11-16 SAT
|
||||
1996-12-23 MON
|
||||
1980-7-2 WED
|
||||
2016-7-17 SUN
|
||||
1947-4-2 WED
|
||||
2046-8-2 THU
|
||||
2087-4-3 THU
|
||||
2009-11-19 THU
|
||||
----------------------
|
||||
|
||||
my output:
|
||||
|
||||
1923
|
||||
2078
|
||||
2080
|
||||
2002
|
||||
1986
|
||||
2022
|
||||
1952
|
||||
2057
|
||||
2092
|
||||
2015
|
||||
-----------------------
|
||||
STD output:
|
||||
1923
|
||||
2078
|
||||
2080
|
||||
2002
|
||||
1986
|
||||
2022
|
||||
1952
|
||||
2057
|
||||
2092
|
||||
2015
|
|
@ -0,0 +1,17 @@
|
|||
//数小木块
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n, i;
|
||||
long long int sum = 0;
|
||||
scanf("%d", &n);
|
||||
for (i = 1; i <= n; i++)
|
||||
{
|
||||
sum += i * (i + 1) / 2;
|
||||
}
|
||||
printf("%lld", sum);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
//15 爬虫
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n, u, d, time = 0;
|
||||
while (scanf("%d %d %d", &n, &u, &d))
|
||||
{
|
||||
if (n == 0 && u == 0 && d == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
time = 0;
|
||||
while (n > 0)
|
||||
{
|
||||
time++;
|
||||
n -= u;
|
||||
if (n <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
time++;
|
||||
n += d;
|
||||
}
|
||||
printf("%d\n", time);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
//2 小熊买糖果
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
int getCandy(int, int);
|
||||
int main()
|
||||
{
|
||||
int k, r;
|
||||
scanf("%d %d", &k, &r);
|
||||
int result = getCandy(k, r);
|
||||
printf("%d", result);
|
||||
return 0;
|
||||
}
|
||||
int getCandy(int k, int r)
|
||||
{
|
||||
int n;
|
||||
for (n = 1; true; n++)
|
||||
{
|
||||
if ((n * k) % 10 == r || (n * k) % 10 == 0)
|
||||
{
|
||||
return n;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
//最大公约数和最小公倍数
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
int lcm(int u,int v);
|
||||
int gcd(int u,int v);
|
||||
int main()
|
||||
{
|
||||
int x,y;
|
||||
scanf("%d%d",&x,&y);
|
||||
printf("%d %d",gcd(x,y),lcm(x,y));
|
||||
return 0;
|
||||
}
|
||||
int gcd(int u,int v)
|
||||
{
|
||||
if(u<v)
|
||||
{
|
||||
int i=v;
|
||||
v=u;
|
||||
u=i;
|
||||
}
|
||||
return v==0?u:gcd(v,u%v);
|
||||
}
|
||||
int lcm(int u,int v)
|
||||
{
|
||||
return u*v/gcd(u,v);
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
//1 魔数
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
bool isMagic(int a);
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
scanf("%d", &n);
|
||||
if (isMagic(n))
|
||||
{
|
||||
printf("YES");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("NO");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
bool isMagic(int a)
|
||||
{
|
||||
int i, aNum[15] = {0};
|
||||
for (i = 9; i >= 0; i--)
|
||||
{
|
||||
aNum[i] = a % 10;
|
||||
a /= 10;
|
||||
if (a == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (; i <= 9; i++)
|
||||
{
|
||||
if (aNum[i] != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (aNum[i + 1] == 4 && aNum[i + 2] == 4)
|
||||
{
|
||||
i += 2;
|
||||
continue;
|
||||
}
|
||||
else if (aNum[i + 1] == 4)
|
||||
{
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
# ifndef MAGIC_H_
|
||||
# define MAGIC_H_
|
||||
bool isMagic(int a);
|
||||
# endif
|
|
@ -0,0 +1,33 @@
|
|||
//快速公交
|
||||
#include<cstdio>
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n,g,r,q,i,j,period,deptTime,arrvTime=0;
|
||||
scanf("%d%d%d",&n,&g,&r);
|
||||
int passTime[n+1],totalPass=0;
|
||||
for(i=0;i<=n;i++)
|
||||
{
|
||||
scanf("%d",&passTime[i]);
|
||||
totalPass+=passTime[i];
|
||||
}
|
||||
scanf("%d",&q);
|
||||
for(i=0;i<q;i++)
|
||||
{
|
||||
scanf("%d",&deptTime);
|
||||
arrvTime=deptTime+passTime[0];
|
||||
for(j=0;j<n;j++)
|
||||
{
|
||||
period=arrvTime%(g+r);
|
||||
if(period>=g)
|
||||
{
|
||||
arrvTime+=r+g-period;
|
||||
}
|
||||
arrvTime+=passTime[j+1];
|
||||
}
|
||||
printf("%d ",arrvTime);
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
//阿迪看医生
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int i, j, n, s[1000], d[1000], time = 0;
|
||||
scanf("%d", &n);
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
scanf("%d %d", &s[i], &d[i]);
|
||||
for (j = s[i]; true; j += d[i])
|
||||
{
|
||||
if (j > time)
|
||||
{
|
||||
time = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("%d", time);
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
//排队喝水
|
||||
#include <cstdio>
|
||||
#include <queue>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
void perform();
|
||||
struct student
|
||||
{
|
||||
int arrTime;
|
||||
int ddlTime;
|
||||
};
|
||||
int main()
|
||||
{
|
||||
int t, i;
|
||||
scanf("%d", &t);
|
||||
for (i = 0; i < t; i++)
|
||||
{
|
||||
perform();
|
||||
}
|
||||
}
|
||||
void perform()
|
||||
{
|
||||
queue<student> q;
|
||||
int n, l, r, i, j, t = 0;
|
||||
student a;
|
||||
scanf("%d", &n);
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
scanf("%d %d", &a.arrTime, &a.ddlTime);
|
||||
q.push(a);
|
||||
}
|
||||
for (t = 1; !q.empty(); t++)
|
||||
{
|
||||
if (q.front().arrTime > t)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
while (q.front().ddlTime < t)
|
||||
{
|
||||
printf("0 ");
|
||||
q.pop();
|
||||
if (q.empty()) //就怕它瞎jb pop给整RE了
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (q.empty())
|
||||
{
|
||||
break;
|
||||
}
|
||||
printf("%d ", t);
|
||||
q.pop();
|
||||
}
|
||||
printf("\n");
|
||||
return;
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
//岁月留痕
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
const int monstr[36] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||
int main()
|
||||
{
|
||||
int i, j, n, cmpstr[36], count29 = 0;
|
||||
;
|
||||
bool find = false;
|
||||
scanf("%d", &n);
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
scanf("%d", &cmpstr[i]);
|
||||
}
|
||||
for (i = 0; i < 12; i++)
|
||||
{
|
||||
find = true;
|
||||
for (j = 0; j < n; j++)
|
||||
{
|
||||
if (cmpstr[j] == monstr[i + j] || (cmpstr[j] == 29 && monstr[i + j] == 28))
|
||||
{
|
||||
if (cmpstr[j] == 29)
|
||||
{
|
||||
count29++;
|
||||
if (count29 == 2)
|
||||
{
|
||||
printf("No");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
find = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (find == true)
|
||||
{
|
||||
printf("Yes");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
printf("No");
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
//小希的新工作
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int ti, li, n, lastEnd = 0, i, j, l, a, count = 0;
|
||||
scanf("%d %d %d", &n, &l, &a);
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
scanf("%d %d", &ti, &li);
|
||||
count += (ti - lastEnd) / a;
|
||||
lastEnd = ti + li;
|
||||
}
|
||||
count += (l - lastEnd) / a;
|
||||
printf("%d", count);
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
//垃圾分类 优化版
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
bool judge(int n);
|
||||
void perform();
|
||||
int main()
|
||||
{
|
||||
int t, i;
|
||||
scanf("%d", &t);
|
||||
for (i = 0; i < t; i++)
|
||||
{
|
||||
perform();
|
||||
}
|
||||
}
|
||||
bool judge(bool x, int n, bool w[], bool b[])
|
||||
{
|
||||
int i, j;
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
if (((x + 2) * (w[i] + 2) + b[i]) % 2 == 0)
|
||||
{
|
||||
x = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
x = 1;
|
||||
}
|
||||
}
|
||||
if (x) //x是奇数,是spam
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
void perform()
|
||||
{
|
||||
long long int countYes = 0, countNo = 0, minX, maxX;
|
||||
int n, i, j, w, b;
|
||||
bool wB[10000], bB[10000], ifOdd, ifEven;
|
||||
scanf("%d %lld %lld", &n, &minX, &maxX);
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
scanf("%d %d", &w, &b);
|
||||
if (w % 2) //规定奇数为1,偶数为0
|
||||
{
|
||||
wB[i] = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
wB[i] = 0;
|
||||
}
|
||||
if (b % 2)
|
||||
{
|
||||
bB[i] = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
bB[i] = 0;
|
||||
}
|
||||
}
|
||||
ifOdd = judge(1, n, wB, bB); //奇数ID是不是spam,下同
|
||||
ifEven = judge(0, n, wB, bB);
|
||||
if (ifOdd && ifEven)
|
||||
{
|
||||
i = maxX - minX + 1;
|
||||
printf("0 %d\n", i);
|
||||
return;
|
||||
}
|
||||
else if ((!ifOdd) && (!ifEven))
|
||||
{
|
||||
i = maxX - minX + 1;
|
||||
printf("%d 0\n", i);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = minX; i <= maxX; i++)
|
||||
{
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
if (ifEven)
|
||||
{
|
||||
countYes++;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
countNo++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ifOdd)
|
||||
{
|
||||
countYes++;
|
||||
}
|
||||
else
|
||||
{
|
||||
countNo++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("%d %d\n", countNo, countYes);
|
||||
return;
|
||||
}
|
After Width: | Height: | Size: 378 KiB |
|
@ -0,0 +1,74 @@
|
|||
//基于神经网络的垃圾分类
|
||||
#include<cstdio>
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
void perform();
|
||||
int main()
|
||||
{
|
||||
int t,i;
|
||||
scanf("%d",&t);
|
||||
for(i=0;i<t;i++)
|
||||
{
|
||||
perform();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
void perform()
|
||||
{
|
||||
int n,i,j,w,b;
|
||||
bool wB[10000],result,bB[10000];
|
||||
long long int countYes=0,countNo=0,minX,maxX;
|
||||
scanf("%d %d %d",&n,&minX,&maxX);
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
scanf("%d %d",&w,&b);
|
||||
if(w%2)//规定奇数为1,偶数为0
|
||||
{
|
||||
wB[i]=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
wB[i]=0;
|
||||
}
|
||||
if(b%2)
|
||||
{
|
||||
bB[i]=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
bB[i]=0;
|
||||
}
|
||||
}
|
||||
for(i=minX;i<=maxX;i++)
|
||||
{
|
||||
if(i%2)
|
||||
{
|
||||
result=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
result=0;
|
||||
}
|
||||
for(j=0;j<n;j++)
|
||||
{
|
||||
if((result&&bB[j])||(!result&&!bB[j])||(result&&!wB[j]&&!bB[j])||(!result&&wB[j]&&bB[j]))//偶的情况
|
||||
{
|
||||
result=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
result=1;
|
||||
}
|
||||
}
|
||||
if(result)
|
||||
{
|
||||
countYes++;
|
||||
}
|
||||
else
|
||||
{
|
||||
countNo++;
|
||||
}
|
||||
}
|
||||
printf("%d %d\n",countNo,countYes);
|
||||
return;
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
//小希与火车
|
||||
#include<cstdio>
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int count,t,m,n,v,l,r,tl;
|
||||
scanf("%d",&t);
|
||||
for(m=0;m<t;m++)
|
||||
{
|
||||
count=0;
|
||||
scanf("%d %d %d %d",&tl,&v,&l,&r);
|
||||
for(n=1;n*v<=tl;n++)
|
||||
{
|
||||
if(n*v>=l&&n*v<=r)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
printf("%d\n",count);
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
#include<cstdio>
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n,i,count=0;
|
||||
scanf("%d",&n);
|
||||
int num[1000]={0};
|
||||
for(i=1;i<=n;i++)
|
||||
{
|
||||
scanf("%d",&num[i]);
|
||||
if(num[i]==1)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
printf("%d\n",count);
|
||||
for(i=1;i<=n;i++)
|
||||
{
|
||||
if(num[i]==1&&i!=1)
|
||||
{
|
||||
printf("%d ",num[i-1]);
|
||||
}
|
||||
}
|
||||
printf("%d",num[n]);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
//松雅的旅馆
|
||||
#include <cstdio>
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n, d, pos[1000], minDist, i, j, count = 0;
|
||||
scanf("%d %d", &n, &d);
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
scanf("%d", &pos[i]);
|
||||
}
|
||||
for (i = pos[0] + 1; i < pos[n - 1]; i++)
|
||||
{
|
||||
minDist = 1 << 30;
|
||||
for (j = 0; j < n; j++)
|
||||
{
|
||||
if (abs(pos[j] - i) < minDist)
|
||||
{
|
||||
minDist = abs(pos[j] - i);
|
||||
}
|
||||
if (i == pos[j] || minDist < d)
|
||||
{
|
||||
minDist = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (minDist == d)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
count += 2;
|
||||
printf("%d", count);
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
//飞机起飞时间安排
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int i, j, n, s, h, m, aTime[100] = {0}, eTime, eHour, eMin;
|
||||
scanf("%d %d", &n, &s);
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
scanf("%d %d", &h, &m);
|
||||
aTime[i] = 60 * h + m;
|
||||
if(i==0&&(aTime[0]>=s+1))
|
||||
{
|
||||
printf("0 0");
|
||||
return 0;
|
||||
}
|
||||
/*if ((aTime[i] - aTime[i - 1] - 2 >= 2 * s) && i != 0)
|
||||
{
|
||||
eTime = aTime[i - 1] + s + 1;
|
||||
eHour = eTime / 60;
|
||||
eMin = eTime % 60;
|
||||
printf("%d %d",eHour,eMin);
|
||||
return 0;
|
||||
}*/
|
||||
}
|
||||
if((aTime[0]-aTime[n-1]+1440-2>=2*s)&&(aTime[n-1]-1439+s>0))
|
||||
{
|
||||
eTime=aTime[n-1]+s+1-1440;
|
||||
eHour=eTime/60;
|
||||
eMin=eTime%60;
|
||||
printf("%d %d",eHour,eMin);
|
||||
return 0;
|
||||
}
|
||||
for(i=1;i<n;i++)
|
||||
{
|
||||
eTime = aTime[i - 1] + s + 1;
|
||||
eHour = eTime / 60;
|
||||
eMin = eTime % 60;
|
||||
printf("%d %d",eHour,eMin);
|
||||
return 0;
|
||||
}
|
||||
eTime=aTime[n-1]+s+1;
|
||||
eHour=eTime/60;
|
||||
eMin=eTime%60;
|
||||
printf("%d %d",eHour,eMin);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
//贪心的阿迪
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int maxNum = 0, count, nAv, x, k, n, m, d;
|
||||
scanf("%d %d %d %d", &n, &k, &m, &d);
|
||||
for (x = m; x >= 1; x--)
|
||||
{
|
||||
nAv = n / x;
|
||||
count = nAv / k * x;
|
||||
if (nAv % k && nAv / k + 1 <= d)
|
||||
{
|
||||
count += x;
|
||||
maxNum = max(count, maxNum);
|
||||
}
|
||||
else if (nAv % k == 0 && nAv / k <= d)
|
||||
{
|
||||
maxNum = max(count, maxNum);
|
||||
}
|
||||
}
|
||||
printf("%d", maxNum);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
//猴导师
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
bool conflict[10000][10000];
|
||||
int ability[10000];
|
||||
int main()
|
||||
{
|
||||
int count, i, j, n, k, a, b;
|
||||
scanf("%d %d", &n, &k);
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
scanf("%d", &ability[i]);
|
||||
}
|
||||
for (i = 0; i < k; i++)
|
||||
{
|
||||
scanf("%d %d", &a, &b);
|
||||
conflict[a - 1][b - 1] = true;
|
||||
conflict[b - 1][a - 1] = true;
|
||||
}
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
count = 0;
|
||||
for (j = 0; j < n; j++)
|
||||
{
|
||||
if (conflict[i][j])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (ability[i] > ability[j])
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
printf("%d ", count);
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
//拜访朋友
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
using namespace std;
|
||||
bool route[1000000];
|
||||
int main()
|
||||
{
|
||||
int n, m, start, end, i, j;
|
||||
scanf("%d %d", &n, &m);
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
scanf("%d %d", &start, &end);
|
||||
start = max(0, start);
|
||||
end = min(end, m);
|
||||
for (j = start; j < end; j++)
|
||||
{
|
||||
route[j] = true;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < m; i++)
|
||||
{
|
||||
if (!route[i])
|
||||
{
|
||||
printf("No");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
printf("Yes");
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
using namespace std;
|
||||
void w();
|
||||
int main()
|
||||
{
|
||||
int t, r;
|
||||
scanf("%d", &t);
|
||||
for (r = 0; r < t; r++)
|
||||
{
|
||||
w();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
void w()
|
||||
{
|
||||
bool water[10001] = {0}, fullWater;
|
||||
int t, tap[1000], i, j, k, n;
|
||||
scanf("%d %d", &n, &k);
|
||||
for (i = 0; i < k; i++)
|
||||
{
|
||||
scanf("%d", &tap[i]);
|
||||
}
|
||||
for (t = 1; true; t++)
|
||||
{
|
||||
fullWater = true;
|
||||
for (i = 0; i < k; i++)
|
||||
{
|
||||
water[max(1, min(tap[i] - t + 1, n))] = 1;
|
||||
water[max(1, min(tap[i] + t - 1, n))] = 1;
|
||||
}
|
||||
for (i = 1; i <= n; i++)
|
||||
{
|
||||
if (!water[i])
|
||||
{
|
||||
fullWater = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (fullWater)
|
||||
{
|
||||
printf("%d\n", t);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//0.00839s
|
|
@ -0,0 +1,49 @@
|
|||
#include <cstdio>
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
void perform();
|
||||
int timeConv(int dist);
|
||||
int max(int a, int b);
|
||||
int main()
|
||||
{
|
||||
int t, i;
|
||||
scanf("%d", &t);
|
||||
for (i = 0; i < t; i++)
|
||||
{
|
||||
perform();
|
||||
}
|
||||
}
|
||||
void perform()
|
||||
{
|
||||
int i, j, maxTime = 0, n, k;
|
||||
int tap[1000];
|
||||
scanf("%d %d", &n, &k);
|
||||
for (i = 0; i < k; i++)
|
||||
{
|
||||
scanf("%d", &tap[i]);
|
||||
}
|
||||
maxTime = tap[0];
|
||||
for (i = 1; i < k; i++)
|
||||
{
|
||||
maxTime = max(timeConv(tap[i] - tap[i - 1] + 1), maxTime);
|
||||
}
|
||||
maxTime = max(maxTime, n - tap[k - 1] + 1);
|
||||
printf("%d\n", maxTime);
|
||||
}
|
||||
int max(int a, int b)
|
||||
{
|
||||
if (a > b)
|
||||
{
|
||||
return a;
|
||||
}
|
||||
else
|
||||
{
|
||||
return b;
|
||||
}
|
||||
}
|
||||
int timeConv(int dist)
|
||||
{
|
||||
return ceil(dist / 2.0);
|
||||
}
|
||||
//0.00992s
|
|
@ -0,0 +1,13 @@
|
|||
#奇数是spam,偶数不是 先非再是
|
||||
for i in range(887,16004):
|
||||
a=i
|
||||
a=a*10+3
|
||||
a=a*6+1
|
||||
a=a*9+9
|
||||
a=a*5+5
|
||||
a=a*8+7
|
||||
a=a*2+7
|
||||
if a%2==0:
|
||||
print("No")
|
||||
else:
|
||||
print("Yes")
|
|
@ -0,0 +1,85 @@
|
|||
#include <iostream>
|
||||
void qsort(int arr[], int low, int high);
|
||||
void Swap(int *a, int *b);
|
||||
void arrange(int a[], int n);
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
cin >> n;
|
||||
|
||||
int a[n];
|
||||
/* 生成数组a */
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
cin >> a[i];
|
||||
}
|
||||
|
||||
arrange(a, n);
|
||||
/* 函数调用 */
|
||||
for (int i = 0; i < n; i++)
|
||||
cout << a[i] << " ";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void arrange(int a[], int n)
|
||||
{
|
||||
int* p = a, *q = a + n - 1; /* 指针p指向数组的第一个元素, 指针q指向数组的最后一个元素 */
|
||||
|
||||
while (p < q) /* 指针p从左向右寻找第一个偶数, 指针q从右向左寻找第一个奇数,将p、q所指向的元素进行交换,然后指针p、q相向移动 */
|
||||
{
|
||||
while(*(p)%2==0&&p<a+n-1)
|
||||
{
|
||||
p++;
|
||||
}
|
||||
while(*(q)%2==1&&q>a)
|
||||
{
|
||||
q--;
|
||||
}
|
||||
if(p<q)
|
||||
{
|
||||
Swap(p,q);
|
||||
p++;
|
||||
q--;
|
||||
}
|
||||
}
|
||||
int m = p - a + p - q;
|
||||
qsort(a, 0, m); /* 调用快速排序对奇数部分排序 */
|
||||
qsort(a, m + 1, n - 1); /* 调用快速排序对偶数部分排序 */
|
||||
}
|
||||
|
||||
void qsort(int *p, int low, int high)
|
||||
{
|
||||
if (high <= low)
|
||||
return;
|
||||
int key = p[low];
|
||||
int i = low, j = high + 1;
|
||||
while (1)
|
||||
{
|
||||
while (p[++i] < key)
|
||||
{
|
||||
if (i == high)
|
||||
break;
|
||||
}
|
||||
while (p[--j] > key)
|
||||
{
|
||||
if (j == low)
|
||||
break;
|
||||
}
|
||||
if (i >= j)
|
||||
break;
|
||||
Swap(&p[i], &p[j]);
|
||||
}
|
||||
Swap(&p[low], &p[j]);
|
||||
qsort(p, low, j - 1);
|
||||
qsort(p, j + 1, high);
|
||||
}
|
||||
|
||||
void Swap(int *a, int *b)
|
||||
{
|
||||
int temp = *a;
|
||||
*a = *b;
|
||||
*b = temp;
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
//字符串反转
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
void reverseStr(char *s);
|
||||
int main()
|
||||
{
|
||||
char str[201];
|
||||
gets(str);
|
||||
reverseStr(str);
|
||||
puts(str);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void reverseStr(char *s)
|
||||
{
|
||||
char *p = s, *q = s;
|
||||
while (*q)
|
||||
q++;
|
||||
q--;
|
||||
while (p < q) /* 将指针p、q所指向位置的字符进行交换,之后指针p、q相向移动 */
|
||||
{
|
||||
|
||||
char x = *q;
|
||||
*q = *p;
|
||||
*p = x;
|
||||
p++;
|
||||
q--;
|
||||
}
|
||||
}
|