## 分类 - 题解

2018-05-01 23:32:05    180    0    0

# A.

#include <algorithm>#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#include <map>#include <queue>#include <set>#include <stack>#include <string>#define mset(a) memset((a), 0, sizeof(a))using namespace std;const int inf = 0x7f7f7f7f;int main() {    // freopen("input","r",stdin);    int n, s, h, m;    cin >> n >> s;    int last = 0, cur;    for (int i = 1; i <= n; ++i) {        cin >> h >> m;        cur = h * 60 + m;        if (i == 1) {            if (cur - last >= s + 1) {                cout << "0 0" << endl;                return 0;            }        } else {            if (cur - last >= s * 2 + 2) {                cout << (last + s + 1) / 60 << ' ' << (last + s + 1) % 60                     << endl;                return 0;            }        }        last = cur;    }    cout << (cur + s + 1) / 60 << ' ' << (cur + s + 1) % 60 << endl;    return 0;}

B.

#include <algorithm>#include <cmath
2017-04-06 09:42:34    142    0    0

# #31. 【UR #2】猪猪侠再战括号序列

$O\left(n\right)$$O(n)$

#include<cstdio>#include<cstring>#include<vector>using namespace std;const int maxn = 200005;char a[maxn];vector<pair<int,int> > ans;int main(){    scanf("%s",a);    int l = 0,r = 0,n = strlen(a)/2;    for(;l<n;++l){        if(a[l]=='(')continue;        if(!r)r = l+1;        for(;a[r]!='(';++r);        swap(a[l],a[r]);        ans.push_back(make_pair(l,r));    }    printf("%d\n",ans.size());    for(int i = 0,lim = ans.size();i<lim;++i)        printf("%d %d\n",ans[i].first+1,ans[i].second+1);    return 0;}

# #48. 【UR #3】核聚变反应强度

2017-04-05 08:47:20    92    0    0

2017-04-04 16:39:55    121    0    0

python太慢了啊，tle救不过来

def calculate(s,a):    return eval(s)t = raw_input().replace('^','**')n = int(raw_input())s = []for i in range(0,n):    s.append(raw_input().replace('^','**'))correct = [1]*naes = [233,499,379,239,277,1096,15532]for a in aes:    ans = calculate(t,a)    for i in range(0,n):        if calculate(s[i],a)!=ans :correct[i] = 0ans = ''for i in range(0,n):    if correct[i]==1 : ans += (chr(ord('A')+i))print ans
2017-04-04 15:43:54    143    0    0

#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>#include<cmath>#include<set>#include<map>#include<vector>#include<stack>#include<queue>#define scan(a) scanf("%d",&a)#define mset(a,b) memset(a,(b),sizeof(a))using namespace std;typedef long long ll;typedef unsigned long long ull;const int inf = 0x3f3f3f3f;const int maxn = 3*60+5;struct people{    int w,id;}c[maxn],a[maxn],b[maxn],d[maxn];bool cmp1(people a,people b){    return a.w<b.w;}int ans1[maxn],ans2[maxn],ans3[maxn];typedef double db;int main(){    int k;    scan(k);    for(int i = 1;i<=3*k;++i)scan(c[i].w),c[i].id 
2017-04-04 11:39:39    103    0    0

$\begin{array}{rl}ans& =\sum _{i=1}^{n}n\mathrm{%}i\\ & =\sum _{i=1}^{n}\left(n-⌊\frac{n}{i}⌋\right)\\ & ={n}^{2}-\sum _{i=1}^{n}⌊\frac{n}{i}⌋\end{array}$

#include<cstdio>using namespace std;typedef long long ll;const ll mod = 1000000007;int main(){    ll n,inv = (-mod/2+mod)%mod;    scanf("%lld",&n);    ll ans = 0;    for(ll i = 1,last;i<=n;i = last+1){        last = n/(n/i);        ans = (ans+(n/i%mod)*((i+last)%mod)%mod*((last-i+1)%mod)%mod*inv%mod)%mod;    }    printf("%lld\n",(((n%mod)*(n%mod)%mod-ans)%mod+mod)%mod);}
2017-04-04 10:47:34    94    0    0

$ans=\left[1|gcd\left(x,y\right)\right]-\left[p|gcd\left(x,y\right)\right]+\left[p\ast q|gcd\left(x,y\right)\right]+...$

2017-04-03 19:39:40    383    0    0

//random#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>#include<cstdlib>#include<ctime>using namespace std;typedef long long ll;const int maxn = 505;int n;struct matrix{    int m[maxn][maxn];    matrix(){        memset(m,0,sizeof(m));    }};matrix operator * (matrix a,matrix b){    matrix ret;    for(int i = 1;i<=n;++i)        for(int j = 1;j<=n;++j)            ret.m[1][j] += a.m[1][i]*b.m[i][j];    return ret;}bool operator == (matrix a,matrix b){    for(int j = 1;j<=n;++j)        if(a.m[1][j]!=b.m[1][j])return false;    return true;}inline int init(){    int x = 0;    char c = getchar();    while(!isdigit(c))
2017-04-04 09:09:00    125    0    0

//分段#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>#include<cmath>#include<set>#include<map>#include<vector>#include<stack>#include<queue>#define scan(a) scanf("%d",&a)#define mset(a,b) memset(a,(b),sizeof(a))using namespace std;typedef long long ll;typedef unsigned long long ull;const int inf = 0x3f3f3f3f;const int maxn = 100005;const int mod = 998244353;int n,a[maxn],ans0,ans1,m;char s[5];int main(){    scan(n);n--,m = 1;    for(int i = 1;i<=n;++i){        scanf("%s
2017-04-03 21:22:00    192    0    0

POJ不支持SRAND！！！！！RE了半小时！！！

#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>#include<cmath>#include<set>#include<map>#include<vector>#include<stack>#include<queue>#include<ctime>#include<cstdlib>#define scan(a) scanf("%d",&a)#define mset(a,b) memset(a,(b),sizeof(a))using namespace std;typedef long long ll;typedef unsigned long long ull;const int inf = 0x3f3f3f3f;const int maxn = 1000005;vector<int> a;int b[maxn],c[maxn],n;int main(){    //srand(time(0));    cin>>n;    for(int i = 0;i<n;++i){        int t;        cin>>t;        a.push_back(t);    }    if(n==1){        printf("0 %d\n",a[0]);        return 0;    }    int l = n/2,r = n-l,T = 0,ansl = -inf,ansr = inf;    while(T++<300){        int sl = 0,sr = 0,cnt = 0;        random_shu`