mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
commit
8fedca2bcb
57
HDOJ/1078.cpp
Normal file
57
HDOJ/1078.cpp
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
#include <algorithm>
|
||||||
|
using namespace std;
|
||||||
|
#define MAXN 101
|
||||||
|
int map[MAXN][MAXN];
|
||||||
|
int dp[MAXN][MAXN];
|
||||||
|
int N;
|
||||||
|
int K;
|
||||||
|
int dfs(int y,int x)
|
||||||
|
{
|
||||||
|
if(dp[y][x]!=0) return dp[y][x];
|
||||||
|
dp[y][x]=map[y][x];
|
||||||
|
for(int i=1;i<=K;i++)
|
||||||
|
{
|
||||||
|
if(x+i<N&&map[y][x]<map[y][x+i])
|
||||||
|
{
|
||||||
|
dp[y][x]=max(dp[y][x],dfs(y,x+i)+map[y][x]);
|
||||||
|
}
|
||||||
|
if(x-i>=0&&map[y][x]<map[y][x-i])
|
||||||
|
{
|
||||||
|
dp[y][x]=max(dp[y][x],dfs(y,x-i)+map[y][x]);
|
||||||
|
}
|
||||||
|
if(y+i<N&&map[y][x]<map[y+i][x])
|
||||||
|
{
|
||||||
|
dp[y][x]=max(dp[y][x],dfs(y+i,x)+map[y][x]);
|
||||||
|
}
|
||||||
|
if(y-i>=0&&map[y][x]<map[y-i][x])
|
||||||
|
{
|
||||||
|
dp[y][x]=max(dp[y][x],dfs(y-i,x)+map[y][x]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dp[y][x];
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int n,k;
|
||||||
|
while(scanf("%d %d",&n,&k)==2&&n!=-1&&k!=-1)
|
||||||
|
{
|
||||||
|
memset(dp,0,sizeof(int)*MAXN*MAXN);
|
||||||
|
memset(map,0,sizeof(int)*MAXN*MAXN);
|
||||||
|
N=n;
|
||||||
|
K=k;
|
||||||
|
for(int i=0;i<N;i++)
|
||||||
|
{
|
||||||
|
for(int j=0;j<N;j++)
|
||||||
|
{
|
||||||
|
scanf("%d",&map[i][j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int ans=dfs(0,0);
|
||||||
|
printf("%d\n",ans);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
92
HDOJ/1166.cpp
Normal file
92
HDOJ/1166.cpp
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
|
int C[131072];
|
||||||
|
|
||||||
|
char cmd[32];
|
||||||
|
|
||||||
|
int getsum(int left,int right,int pos,int leftbound,int rightbound)
|
||||||
|
{
|
||||||
|
if(left<=leftbound&&right>=rightbound)
|
||||||
|
{
|
||||||
|
return C[pos];
|
||||||
|
}
|
||||||
|
if(right<leftbound||left>rightbound)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int a=getsum(left,right,2*pos+1,leftbound,(leftbound+rightbound)/2);
|
||||||
|
int b=getsum(left,right,2*pos+2,(leftbound+rightbound)/2+1,rightbound);
|
||||||
|
return a+b;
|
||||||
|
}
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int t;
|
||||||
|
scanf("%d",&t);
|
||||||
|
for(int itt=1;itt<=t;itt++)
|
||||||
|
{
|
||||||
|
printf("Case %d:\n",itt);
|
||||||
|
int N;
|
||||||
|
scanf("%d",&N);
|
||||||
|
int realn=1;
|
||||||
|
while(realn<N)
|
||||||
|
{
|
||||||
|
realn*=2;
|
||||||
|
}
|
||||||
|
memset(C,0,sizeof(int)*realn);
|
||||||
|
for(int i=0;i<N;i++)
|
||||||
|
{
|
||||||
|
scanf("%d",&C[realn-1+i]);
|
||||||
|
}
|
||||||
|
int start=(realn-1)/2;
|
||||||
|
while(start>0)
|
||||||
|
{
|
||||||
|
int L=start+1;
|
||||||
|
for(int i=0;i<L;i++)
|
||||||
|
{
|
||||||
|
C[start+i]=C[2*(start+i)+1]+C[2*(start+i)+2];
|
||||||
|
}
|
||||||
|
start=(start-1)/2;
|
||||||
|
}
|
||||||
|
C[0]=C[1]+C[2];
|
||||||
|
while(scanf("%s",cmd)==1)
|
||||||
|
{
|
||||||
|
if(strcmp(cmd,"End")==0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
int a,b;
|
||||||
|
scanf("%d %d",&a,&b);
|
||||||
|
if(strcmp(cmd,"Query")==0)
|
||||||
|
{
|
||||||
|
int ans=getsum(a-1,b-1,0,0,realn-1);
|
||||||
|
printf("%d\n",ans);
|
||||||
|
}
|
||||||
|
else if(strcmp(cmd,"Add")==0)
|
||||||
|
{
|
||||||
|
int pos=realn-1+a-1;
|
||||||
|
while(pos>0)
|
||||||
|
{
|
||||||
|
C[pos]+=b;
|
||||||
|
pos=(pos-1)/2;
|
||||||
|
}
|
||||||
|
C[0]+=b;
|
||||||
|
}
|
||||||
|
else if(strcmp(cmd,"Sub")==0)
|
||||||
|
{
|
||||||
|
int pos=realn-1+a-1;
|
||||||
|
while(pos>0)
|
||||||
|
{
|
||||||
|
C[pos]-=b;
|
||||||
|
pos=(pos-1)/2;
|
||||||
|
}
|
||||||
|
C[0]-=b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}/// end of for(...)
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
42
HDOJ/1501_CSDN_dfs.cpp
Normal file
42
HDOJ/1501_CSDN_dfs.cpp
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstring>
|
||||||
|
//#define LOCAL
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
const int MAXN=205;
|
||||||
|
|
||||||
|
char a[MAXN],b[MAXN],all[2*MAXN-5];
|
||||||
|
int lenA,lenB,lenAll;
|
||||||
|
|
||||||
|
bool DFS(int posA,int posB,int posAll) {
|
||||||
|
if(posA==lenA&&posB==lenB)
|
||||||
|
return true;
|
||||||
|
if(posA<lenA&&a[posA]==all[posAll]&&DFS(posA+1,posB,posAll+1))
|
||||||
|
return true;
|
||||||
|
if(posB<lenB&&b[posB]==all[posAll]&&DFS(posA,posB+1,posAll+1))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
#ifdef LOCAL
|
||||||
|
freopen("in.txt","r",stdin);
|
||||||
|
//freopen("out.txt","w",stdout);
|
||||||
|
#endif
|
||||||
|
int T,cnt=0;
|
||||||
|
scanf("%d",&T);
|
||||||
|
while(T--) {
|
||||||
|
printf("Data set %d: ",++cnt);
|
||||||
|
scanf("%s%s%s",a,b,all);
|
||||||
|
lenA=strlen(a);
|
||||||
|
lenB=strlen(b);
|
||||||
|
lenAll=strlen(all);
|
||||||
|
if((all[0]!=a[0]&&all[0]!=b[0])||(all[lenAll-1]!=a[lenA-1]&&all[lenAll-1]!=b[lenB-1])) {//剪枝,不加上就会TLE
|
||||||
|
printf("no\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
printf("%s\n",DFS(0,0,0)?"yes":"no");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
36
HDOJ/1501_CSDN_dp.cpp
Normal file
36
HDOJ/1501_CSDN_dp.cpp
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstring>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int n,m,al,bl,cl,lim;
|
||||||
|
char a[205],b[205],c[405];
|
||||||
|
bool dp[205][205];//dp[i][j]表示串a的前i个字符与串b的前j个字符是否能形成串c的前i+j个字符
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int T,kase=0;
|
||||||
|
scanf("%d",&T);
|
||||||
|
while(kase<T) {
|
||||||
|
scanf("%s%s%s",a+1,b+1,c+1);
|
||||||
|
al=strlen(a+1);
|
||||||
|
bl=strlen(b+1);
|
||||||
|
cl=al+bl;
|
||||||
|
memset(dp,false,sizeof(dp));
|
||||||
|
dp[0][0]=true;
|
||||||
|
for(int k=1;k<=cl;++k) {//枚举串c的字符
|
||||||
|
lim=min(k,al);
|
||||||
|
for(int i=max(1,k-bl);i<=lim;++i) {//在a串上进行状态转移
|
||||||
|
if(dp[i-1][k-i]&&a[i]==c[k])//如果串a前i-1个字符与串b前k-i个字符能构成串c的前k个字符,并且当前a[i]==c[k]
|
||||||
|
dp[i][k-i]=true;
|
||||||
|
}
|
||||||
|
lim=min(k,bl);
|
||||||
|
for(int j=max(1,k-al);j<=lim;++j) {//在b串上进行状态转移
|
||||||
|
if(dp[k-j][j-1]&&b[j]==c[k])//如果串a前k-j个字符与串b前j-1个字符能构成串c的前k个字符,并且当前b[j]==c[k]
|
||||||
|
dp[k-j][j]=true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("Data set %d: %s\n",++kase,dp[al][bl]?"yes":"no");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
59
HDOJ/1501_dfs.cpp
Normal file
59
HDOJ/1501_dfs.cpp
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
char a[300];
|
||||||
|
char b[300];
|
||||||
|
char c[700];
|
||||||
|
|
||||||
|
int lena,lenb,lenc;
|
||||||
|
bool dfs(int pos_in_a,int pos_in_b,int pos_in_c)
|
||||||
|
{
|
||||||
|
if(pos_in_a==lena&&pos_in_b==lenb)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(pos_in_a<lena&&a[pos_in_a]==c[pos_in_c]&&dfs(pos_in_a+1,pos_in_b,pos_in_c+1))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(pos_in_b<lenb&&b[pos_in_b]==c[pos_in_c]&&dfs(pos_in_a,pos_in_b+1,pos_in_c+1))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int t;
|
||||||
|
scanf("%d",&t);
|
||||||
|
for(int tt=1;tt<=t;tt++)
|
||||||
|
{
|
||||||
|
scanf("%s %s %s",a,b,c);
|
||||||
|
printf("Data set %d: ",tt);
|
||||||
|
lena=strlen(a);
|
||||||
|
lenb=strlen(b);
|
||||||
|
lenc=strlen(c);
|
||||||
|
if(a[0]!=c[0]&&b[0]!=c[0])
|
||||||
|
{
|
||||||
|
printf("no\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(a[lena-1]!=c[lenc-1]&&b[lenb-1]!=c[lenc-1])
|
||||||
|
{
|
||||||
|
printf("no\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
bool ans=dfs(0,0,0);
|
||||||
|
if(ans)
|
||||||
|
{
|
||||||
|
printf("yes\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("no\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
105
POJ/3040.cpp
Normal file
105
POJ/3040.cpp
Normal file
|
@ -0,0 +1,105 @@
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
struct cash
|
||||||
|
{
|
||||||
|
int value;
|
||||||
|
int amount;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool cmp(const cash& a,const cash& b)
|
||||||
|
{
|
||||||
|
return a.value<b.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
int need[64];
|
||||||
|
int makedayfrom(vector<cash>& vec,int C)
|
||||||
|
{
|
||||||
|
memset(need,0,sizeof(int)*64);
|
||||||
|
int N=vec.size();
|
||||||
|
int left=C;
|
||||||
|
for(int i=N-1;i>=0;i--)
|
||||||
|
{//
|
||||||
|
if(vec.at(i).amount>0&&left>0)
|
||||||
|
{
|
||||||
|
int x=left/vec.at(i).value;
|
||||||
|
x=min(x,vec.at(i).amount);
|
||||||
|
need[i]=x;
|
||||||
|
left-=x*vec.at(i).value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(left>0)
|
||||||
|
{
|
||||||
|
for(int i=0;i<N;i++)
|
||||||
|
{
|
||||||
|
if(vec.at(i).amount>need[i]&&left>0)
|
||||||
|
{
|
||||||
|
int x=left/vec.at(i).value;
|
||||||
|
if(x==0)
|
||||||
|
{
|
||||||
|
/// try to make x = 1
|
||||||
|
need[i]++;
|
||||||
|
left=0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(left>0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
int canpayday=2<<29;
|
||||||
|
for(int i=0;i<64;i++)
|
||||||
|
{
|
||||||
|
if(need[i]>0)
|
||||||
|
{
|
||||||
|
canpayday=min(canpayday,vec.at(i).amount/need[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(canpayday<=0) return -1;
|
||||||
|
for(int i=0;i<N;i++)
|
||||||
|
{
|
||||||
|
if(need[i]>0)
|
||||||
|
{
|
||||||
|
vec.at(i).amount-=canpayday*need[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return canpayday;
|
||||||
|
|
||||||
|
}
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int N,C;
|
||||||
|
scanf("%d %d",&N,&C);
|
||||||
|
vector<cash> vec;
|
||||||
|
int ans=0;
|
||||||
|
for(int i=0;i<N;i++)
|
||||||
|
{
|
||||||
|
cash s;
|
||||||
|
scanf("%d %d",&s.value,&s.amount);
|
||||||
|
vec.push_back(s);
|
||||||
|
}
|
||||||
|
sort(vec.begin(),vec.end(),cmp);
|
||||||
|
for(int i=N-1;i>=0;i--)
|
||||||
|
{
|
||||||
|
if(vec.at(i).value>=C)
|
||||||
|
{
|
||||||
|
ans+=vec.at(i).amount;
|
||||||
|
vec.pop_back();
|
||||||
|
}
|
||||||
|
else break;
|
||||||
|
}
|
||||||
|
int tmp;
|
||||||
|
while((tmp=makedayfrom(vec,C))>0)
|
||||||
|
{
|
||||||
|
ans+=tmp;
|
||||||
|
}
|
||||||
|
printf("%d\n",ans);
|
||||||
|
return 0;
|
||||||
|
}
|
72
POJ/3040_aiuxian.cpp
Normal file
72
POJ/3040_aiuxian.cpp
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
#include<stdio.h>
|
||||||
|
#include<string.h>
|
||||||
|
#include<iostream>
|
||||||
|
#include<algorithm>
|
||||||
|
using namespace std;
|
||||||
|
const int maxn=30;
|
||||||
|
struct node
|
||||||
|
{
|
||||||
|
int x,y;//存储钱的大小和数量
|
||||||
|
bool operator<(const node c)const
|
||||||
|
{
|
||||||
|
return x>c.x;
|
||||||
|
}
|
||||||
|
}num[maxn];
|
||||||
|
int need[maxn],n,c,kj;
|
||||||
|
//need[]函数是是存储需要哪些钱币的组合
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
while(scanf("%d%d",&n,&c)!=EOF)
|
||||||
|
{
|
||||||
|
for(int i=0;i<n;i++)
|
||||||
|
scanf("%d%d",&num[i].x,&num[i].y);
|
||||||
|
sort(num,num+n);//排序是第一步
|
||||||
|
kj=0;
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
int sum=c;
|
||||||
|
memset(need,0,sizeof(need));
|
||||||
|
for(int i=0;i<n;i++)//这个for循环是用于找出钱币的组合方法
|
||||||
|
{
|
||||||
|
if(sum>0)
|
||||||
|
{
|
||||||
|
int t=sum/num[i].x;
|
||||||
|
if(t==0)
|
||||||
|
continue;
|
||||||
|
t=min(t,num[i].y);
|
||||||
|
need[i]=t;
|
||||||
|
sum-=t*num[i].x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(sum>0)//如果在上面的组合中没有使sum变为0,则从小到大选择最小的面值组合,这样使面值超过的最小化
|
||||||
|
{
|
||||||
|
for(int i=n-1;i>=0;i--)
|
||||||
|
if(num[i].y&&num[i].x>=sum)
|
||||||
|
{
|
||||||
|
sum=0;
|
||||||
|
need[i]++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(sum>0)//如果组合不能达到c,怎么说明搜索结束
|
||||||
|
break;
|
||||||
|
int cc=2e9;
|
||||||
|
for(int i=n-1;i>=0;i--)//找出这个组合成的面值中最小的数量,同时减去它们。
|
||||||
|
{
|
||||||
|
if(need[i])
|
||||||
|
{
|
||||||
|
cc=min(cc,num[i].y/need[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
kj+=cc;
|
||||||
|
for(int i=0;i<n;i++)
|
||||||
|
if(need[i])
|
||||||
|
{
|
||||||
|
num[i].y-=cc*need[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("%d\n",kj);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
102
POJ/3040_hankcs.cpp
Normal file
102
POJ/3040_hankcs.cpp
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include <functional>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <limits>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
typedef pair<int, int> Coin; // 硬币 面值和数量
|
||||||
|
Coin coin[20];
|
||||||
|
int need[20];
|
||||||
|
|
||||||
|
///////////////////////////SubMain//////////////////////////////////
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
#ifndef ONLINE_JUDGE
|
||||||
|
freopen("in.txt", "r", stdin);
|
||||||
|
freopen("out.txt", "w", stdout);
|
||||||
|
#endif
|
||||||
|
int N, C;
|
||||||
|
cin >> N >> C;
|
||||||
|
for (int i = 0; i < N; ++i)
|
||||||
|
{
|
||||||
|
cin >> coin[i].first >> coin[i].second;
|
||||||
|
}
|
||||||
|
int week = 0;
|
||||||
|
// 面额不小于C的一定可以支付一周
|
||||||
|
for (int i = 0; i < N; ++i)
|
||||||
|
{
|
||||||
|
if (coin[i].first >= C)
|
||||||
|
{
|
||||||
|
week += coin[i].second;
|
||||||
|
coin[i].second = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sort(coin, coin + N, greater<Coin>());
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
int sum = C; // 等待凑足的sum
|
||||||
|
memset(need, 0, sizeof(need));
|
||||||
|
// 从大到小
|
||||||
|
for (int i = 0; i < N; ++i)
|
||||||
|
{
|
||||||
|
if (sum > 0 && coin[i].second > 0)
|
||||||
|
{
|
||||||
|
int can_use = min(coin[i].second,
|
||||||
|
sum / coin[i].first);
|
||||||
|
if (can_use > 0)
|
||||||
|
{
|
||||||
|
sum -= can_use * coin[i].first;
|
||||||
|
need[i] = can_use;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 从小到大
|
||||||
|
for (int i = N - 1; i >= 0; --i)
|
||||||
|
{
|
||||||
|
if (sum > 0 && coin[i].second > 0)
|
||||||
|
{
|
||||||
|
int can_use = min(coin[i].second - need[i], // 上个loop用掉了一些
|
||||||
|
(sum + coin[i].first - 1) / coin[i].first); // 允许多出不超过一个面值的金额
|
||||||
|
if (can_use > 0)
|
||||||
|
{
|
||||||
|
sum -= can_use * coin[i].first;
|
||||||
|
need[i] += can_use;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(sum > 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
int add_up = numeric_limits<int>::max(); // 凑起来的week数
|
||||||
|
// add_up多少个最优的week 受限于 每种面值能满足最优解下的需求个数多少次
|
||||||
|
for (int i = 0; i < N; ++i)
|
||||||
|
{
|
||||||
|
if (need[i] == 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
add_up = min(add_up, coin[i].second / need[i]);
|
||||||
|
}
|
||||||
|
week += add_up;
|
||||||
|
// 最优解生效,更新剩余硬币数量
|
||||||
|
for (int i = 0; i < N; ++i)
|
||||||
|
{
|
||||||
|
if (need[i] == 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
coin[i].second -= add_up * need[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout << week << endl;
|
||||||
|
#ifndef ONLINE_JUDGE
|
||||||
|
fclose(stdin);
|
||||||
|
fclose(stdout);
|
||||||
|
system("out.txt");
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
///////////////////////////End Sub//////////////////////////////////
|
81
POJ/3040_tuicool.cpp
Normal file
81
POJ/3040_tuicool.cpp
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include<algorithm>
|
||||||
|
#include<math.h>
|
||||||
|
#include<stdio.h>
|
||||||
|
#include<string.h>
|
||||||
|
const int INF=0x3f3f3f3f;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
struct node
|
||||||
|
{
|
||||||
|
int val,mou;//面值和数目
|
||||||
|
} mon[25];
|
||||||
|
int n,c;
|
||||||
|
int need[25];//一种方案所需各面值的数目
|
||||||
|
bool cmp(node a,node b)
|
||||||
|
{
|
||||||
|
return a.val<b.val;
|
||||||
|
}
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int i,ans,ti,rest,lim,mday;
|
||||||
|
|
||||||
|
while(~scanf("%d%d",&n,&c))
|
||||||
|
{
|
||||||
|
ans=0;
|
||||||
|
lim=-1;
|
||||||
|
for(i=0;i<n;i++)
|
||||||
|
scanf("%d%d",&mon[i].val,&mon[i].mou);
|
||||||
|
sort(mon,mon+n,cmp);
|
||||||
|
for(i=n-1;i>=0;i--)
|
||||||
|
if(mon[i].val>=c)//如果面值大于c直接加数目就行了
|
||||||
|
ans+=mon[i].mou;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lim=i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
memset(need,0,sizeof need);
|
||||||
|
rest=c;
|
||||||
|
for(i=lim;i>=0;i--)//尽可能用大面值凑够
|
||||||
|
{
|
||||||
|
if(!mon[i].mou||!rest)
|
||||||
|
continue;
|
||||||
|
ti=rest/mon[i].val;
|
||||||
|
ti=min(ti,mon[i].mou);
|
||||||
|
need[i]=ti;
|
||||||
|
rest-=ti*mon[i].val;
|
||||||
|
}
|
||||||
|
if(rest)//没凑够的话。只能往回找最小的面值凑够。保证损失的钱最少
|
||||||
|
{
|
||||||
|
for(i=0;i<=lim;i++)
|
||||||
|
{
|
||||||
|
if(mon[i].val>=rest&&(mon[i].mou-need[i]))
|
||||||
|
{
|
||||||
|
need[i]++;
|
||||||
|
rest=0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(rest)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
mday=INF;
|
||||||
|
for(i=0;i<=lim;i++)
|
||||||
|
if(need[i])
|
||||||
|
mday=min(mday,mon[i].mou/need[i]);//得出该种方案能支付的最大周数
|
||||||
|
ans+=mday;
|
||||||
|
for(i=0;i<=lim;i++)
|
||||||
|
mon[i].mou-=mday*need[i];
|
||||||
|
}
|
||||||
|
printf("%d\n",ans);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
11
|
||||||
|
6 1
|
||||||
|
4 1
|
||||||
|
*/
|
74
POJ/3190.cpp
Normal file
74
POJ/3190.cpp
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
#include <functional>
|
||||||
|
#include <queue>
|
||||||
|
#include <algorithm>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
|
struct cow
|
||||||
|
{
|
||||||
|
int start,over;
|
||||||
|
int pos;
|
||||||
|
bool operator <(const cow& b) const
|
||||||
|
{
|
||||||
|
if(over==b.over)
|
||||||
|
return start>b.start;
|
||||||
|
return over>b.over;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
bool cmp(const cow& a,const cow& b)
|
||||||
|
{
|
||||||
|
if(a.start==b.start) return a.over<b.over;
|
||||||
|
return a.start<b.start;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
priority_queue<cow> bus;
|
||||||
|
int use[50001];
|
||||||
|
cow cowx[50001];
|
||||||
|
|
||||||
|
int cnt=1;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
while(scanf("%d",&n)==1)
|
||||||
|
{
|
||||||
|
|
||||||
|
for(int i=0; i<n; i++)
|
||||||
|
{
|
||||||
|
int a,b;
|
||||||
|
scanf("%d %d",&a,&b);
|
||||||
|
cowx[i].start=a;
|
||||||
|
cowx[i].over=b;
|
||||||
|
cowx[i].pos=i;
|
||||||
|
}
|
||||||
|
sort(cowx,cowx+n,cmp);
|
||||||
|
use[cowx[0].pos]=1;
|
||||||
|
bus.push(cowx[0]);
|
||||||
|
for(int i=1; i<n; i++)
|
||||||
|
{
|
||||||
|
if(!bus.empty()&&bus.top().over<cowx[i].start)
|
||||||
|
{
|
||||||
|
use[cowx[i].pos]=use[bus.top().pos];
|
||||||
|
bus.pop();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++cnt;
|
||||||
|
use[cowx[i].pos]=cnt;
|
||||||
|
}
|
||||||
|
bus.push(cowx[i]);
|
||||||
|
}
|
||||||
|
printf("%d\n",cnt);
|
||||||
|
for(int i=0; i<n; i++)
|
||||||
|
{
|
||||||
|
printf("%d\n",use[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
63
POJ/3190_csdn.cpp
Normal file
63
POJ/3190_csdn.cpp
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
#include<cstdio>
|
||||||
|
#include<cstring>
|
||||||
|
#include<iostream>
|
||||||
|
#include<algorithm>
|
||||||
|
#include<queue>
|
||||||
|
using namespace std;
|
||||||
|
const int maxn=60000;
|
||||||
|
int n,use[maxn];
|
||||||
|
struct Node
|
||||||
|
{
|
||||||
|
int l;
|
||||||
|
int r;
|
||||||
|
int pos;
|
||||||
|
bool operator <(const Node &a)const
|
||||||
|
{
|
||||||
|
if(r==a.r)
|
||||||
|
return l>a.l;
|
||||||
|
return r>a.r;
|
||||||
|
}
|
||||||
|
}a[maxn];
|
||||||
|
priority_queue<Node> q;
|
||||||
|
bool cmp(Node a,Node b)
|
||||||
|
{
|
||||||
|
if(a.l==b.l)
|
||||||
|
return a.r<b.r;
|
||||||
|
return a.l<b.l;
|
||||||
|
}
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
while(scanf("%d",&n)!=EOF)
|
||||||
|
{
|
||||||
|
for(int i=0;i<n;i++)
|
||||||
|
{
|
||||||
|
scanf("%d%d",&a[i].l,&a[i].r);
|
||||||
|
a[i].pos=i;
|
||||||
|
}
|
||||||
|
sort(a,a+n,cmp);
|
||||||
|
q.push(a[0]);
|
||||||
|
int now=0,ans=1;
|
||||||
|
use[a[0].pos]=1;
|
||||||
|
for(int i=1;i<n;i++)
|
||||||
|
{
|
||||||
|
if(!q.empty()&&q.top().r<a[i].l)
|
||||||
|
{
|
||||||
|
use[a[i].pos]=use[q.top().pos];
|
||||||
|
q.pop();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ans++;
|
||||||
|
use[a[i].pos]=ans;
|
||||||
|
}
|
||||||
|
q.push(a[i]);
|
||||||
|
}
|
||||||
|
printf("%d\n",ans);
|
||||||
|
for(int i=0;i<n;i++)
|
||||||
|
printf("%d\n",use[i]);
|
||||||
|
while(!q.empty())
|
||||||
|
q.pop();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
[English](https://github.com/Kiritow/OJ-Problems-Source#oj-problems-source) | [中文(简体)](https://github.com/Kiritow/OJ-Problems-Source#oj问题源代码)
|
[English](#oj-problems-source) | [中文(简体)](#oj问题源代码)
|
||||||
# OJ-Problems-Source
|
# OJ-Problems-Source
|
||||||
Source of **AC** Problems on different OJ.
|
Source of **AC** Problems on different OJ.
|
||||||
If you want to publish your source file, just contact me via GitHub~
|
If you want to publish your source file, just contact me via GitHub~
|
||||||
|
|
59
RQNOJ/600.cpp
Normal file
59
RQNOJ/600.cpp
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
#include <algorithm>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
#define MAXM 100000
|
||||||
|
#define MAXN 20000
|
||||||
|
struct ppk
|
||||||
|
{
|
||||||
|
int a,b,c;
|
||||||
|
};
|
||||||
|
bool cmp(const ppk& a,const ppk& b)
|
||||||
|
{
|
||||||
|
return a.c>b.c;
|
||||||
|
}
|
||||||
|
int f[MAXN*2];
|
||||||
|
ppk X[MAXM];
|
||||||
|
|
||||||
|
int get(int x)
|
||||||
|
{
|
||||||
|
if(x==f[x]) return x;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
f[x]=get(f[x]);
|
||||||
|
return f[x];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int n,m;
|
||||||
|
scanf("%d %d",&n,&m);
|
||||||
|
for(int i=1;i<=n*2;i++)
|
||||||
|
{
|
||||||
|
f[i]=i;
|
||||||
|
}
|
||||||
|
for(int i=0;i<m;i++)
|
||||||
|
{
|
||||||
|
scanf("%d %d %d",&X[i].a,&X[i].b,&X[i].c);
|
||||||
|
}
|
||||||
|
sort(X,X+m,cmp);
|
||||||
|
for(int s=0;s<m;s++)
|
||||||
|
{
|
||||||
|
int x=get(X[s].a);
|
||||||
|
int y=get(X[s].b);
|
||||||
|
if(x==y)
|
||||||
|
{
|
||||||
|
printf("%d\n",X[s].c);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int w=get(X[s].a+n);
|
||||||
|
int t=get(X[s].b+n);
|
||||||
|
f[x]=t;
|
||||||
|
f[y]=w;
|
||||||
|
}
|
||||||
|
printf("0\n");
|
||||||
|
return 0;
|
||||||
|
}
|
2
RQNOJ/Readme.md
Normal file
2
RQNOJ/Readme.md
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
#RenQing Net Online Judge (RQNOJ)
|
||||||
|
[RQNOJ Home Page](http://www.rqnoj.cn/ "Welcome to RQNOJ")
|
53
SDUSTOJ/1795_cnblogs.cpp
Normal file
53
SDUSTOJ/1795_cnblogs.cpp
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
/* ***********************************************
|
||||||
|
Author :devil
|
||||||
|
Created Time :2016/4/26 16:10:39
|
||||||
|
************************************************ */
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstring>
|
||||||
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <vector>
|
||||||
|
#include <queue>
|
||||||
|
#include <set>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
#include <cmath>
|
||||||
|
#include <stdlib.h>
|
||||||
|
using namespace std;
|
||||||
|
typedef long long LL;
|
||||||
|
const int N=2e6+7;
|
||||||
|
int a[N],b[N];
|
||||||
|
long long sum[N];
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
//freopen("in.txt","r",stdin);
|
||||||
|
int n,x;
|
||||||
|
while(~scanf("%d",&n))
|
||||||
|
{
|
||||||
|
int ma=0;
|
||||||
|
memset(a,0,sizeof(a));
|
||||||
|
memset(b,0,sizeof(b));
|
||||||
|
memset(sum,0,sizeof(sum));
|
||||||
|
for(int i=0;i<n;i++)
|
||||||
|
{
|
||||||
|
scanf("%d",&x);
|
||||||
|
ma=max(ma,x);
|
||||||
|
a[x]++;
|
||||||
|
}
|
||||||
|
for(int i=1;i<=ma*2+1;i++)
|
||||||
|
{
|
||||||
|
sum[i]=sum[i-1]+a[i]*i;
|
||||||
|
b[i]=b[i-1]+a[i];
|
||||||
|
}
|
||||||
|
LL ans=1e12+10;
|
||||||
|
for(int i=1;i<=ma;i++)
|
||||||
|
{
|
||||||
|
LL now=sum[i-1];
|
||||||
|
for(int j=1;i*j<=ma;j++)
|
||||||
|
now=now+(b[i*(j+1)-1]-b[i*j-1])*j+sum[i*(j+1)-1]-sum[i*j]-(b[i*(j+1)-1]-b[i*j])*j*i;
|
||||||
|
ans=min(ans,now);
|
||||||
|
}
|
||||||
|
printf("%lld\n",ans);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
128
SDUSTOJ/1796_cnblogs.cpp
Normal file
128
SDUSTOJ/1796_cnblogs.cpp
Normal file
|
@ -0,0 +1,128 @@
|
||||||
|
/* ***********************************************
|
||||||
|
Author :devil
|
||||||
|
Created Time :2016/4/26 13:11:52
|
||||||
|
************************************************ */
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstring>
|
||||||
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <vector>
|
||||||
|
#include <queue>
|
||||||
|
#include <set>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
#include <cmath>
|
||||||
|
#include <stdlib.h>
|
||||||
|
using namespace std;
|
||||||
|
const int N=100005;
|
||||||
|
int n,a[N],b[N],tree[N<<2];
|
||||||
|
void build1(int node,int l,int r)
|
||||||
|
{
|
||||||
|
if(l==r)
|
||||||
|
{
|
||||||
|
tree[node]=N;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
int m=(l+r)>>1;
|
||||||
|
build1(node<<1,l,m);
|
||||||
|
build1(node<<1|1,m+1,r);
|
||||||
|
tree[node]=min(tree[node<<1],tree[node<<1|1]);
|
||||||
|
}
|
||||||
|
void update1(int node,int l,int r,int p)
|
||||||
|
{
|
||||||
|
if(l==r)
|
||||||
|
{
|
||||||
|
tree[node]=b[p];
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
int m=(l+r)>>1;
|
||||||
|
if(a[p]<=m) update1(node<<1,l,m,p);
|
||||||
|
else update1(node<<1|1,m+1,r,p);
|
||||||
|
tree[node]=min(tree[node<<1],tree[node<<1|1]);
|
||||||
|
}
|
||||||
|
int query1(int node,int l,int r,int p)
|
||||||
|
{
|
||||||
|
if(l>=p) return tree[node];
|
||||||
|
int m=(l+r)>>1,ans;
|
||||||
|
ans=query1(node<<1|1,m+1,r,p);
|
||||||
|
if(p<=m) ans=min(ans,query1(node<<1,l,m,p));
|
||||||
|
return ans;
|
||||||
|
}
|
||||||
|
void build2(int node,int l,int r)
|
||||||
|
{
|
||||||
|
if(l==r)
|
||||||
|
{
|
||||||
|
tree[node]=0;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
int m=(l+r)>>1;
|
||||||
|
build2(node<<1,l,m);
|
||||||
|
build2(node<<1|1,m+1,r);
|
||||||
|
tree[node]=max(tree[node<<1],tree[node<<1|1]);
|
||||||
|
}
|
||||||
|
void update2(int node,int l,int r,int p)
|
||||||
|
{
|
||||||
|
if(l==r)
|
||||||
|
{
|
||||||
|
tree[node]=b[p];
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
int m=(l+r)>>1;
|
||||||
|
if(a[p]<=m) update2(node<<1,l,m,p);
|
||||||
|
else update2(node<<1|1,m+1,r,p);
|
||||||
|
tree[node]=max(tree[node<<1],tree[node<<1|1]);
|
||||||
|
}
|
||||||
|
int query2(int node,int l,int r,int p)
|
||||||
|
{
|
||||||
|
if(r<=p) return tree[node];
|
||||||
|
int m=(l+r)>>1,ans;
|
||||||
|
ans=query2(node<<1,l,m,p);
|
||||||
|
if(p>m) ans=max(ans,query2(node<<1|1,m+1,r,p));
|
||||||
|
return ans;
|
||||||
|
}
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
//freopen("in.txt","r",stdin);
|
||||||
|
while(~scanf("%d",&n))
|
||||||
|
{
|
||||||
|
int x,flag=1;
|
||||||
|
for(int i=1; i<=n; i++)
|
||||||
|
{
|
||||||
|
scanf("%d",&x);
|
||||||
|
a[x]=i;
|
||||||
|
}
|
||||||
|
for(int i=1; i<=n; i++)
|
||||||
|
{
|
||||||
|
scanf("%d",&x);
|
||||||
|
b[x]=i;
|
||||||
|
}
|
||||||
|
build1(1,1,n);
|
||||||
|
for(int i=n; i>0; i--)
|
||||||
|
{
|
||||||
|
if(a[i]<=b[i]&&b[i]>query1(1,1,n,a[i]))
|
||||||
|
{
|
||||||
|
flag=0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
update1(1,1,n,i);
|
||||||
|
}
|
||||||
|
if(!flag)
|
||||||
|
{
|
||||||
|
printf("NO\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
build2(1,1,n);
|
||||||
|
for(int i=1; i<=n; i++)
|
||||||
|
{
|
||||||
|
if(a[i]>=b[i]&&b[i]<query2(1,1,n,a[i]))
|
||||||
|
{
|
||||||
|
flag=0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
update2(1,1,n,i);
|
||||||
|
}
|
||||||
|
if(!flag) printf("NO\n");
|
||||||
|
else printf("YES\n");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
93
SDUSTOJ/1799_cnblogs.cpp
Normal file
93
SDUSTOJ/1799_cnblogs.cpp
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
/* ***********************************************
|
||||||
|
Author :devil
|
||||||
|
Created Time :2016/4/26 22:47:45
|
||||||
|
************************************************ */
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstring>
|
||||||
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <vector>
|
||||||
|
#include <queue>
|
||||||
|
#include <set>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
#include <cmath>
|
||||||
|
#include <stdlib.h>
|
||||||
|
using namespace std;
|
||||||
|
#define inf 0x3f3f3f3f
|
||||||
|
#define maxn 1010
|
||||||
|
struct node
|
||||||
|
{
|
||||||
|
int v,d;
|
||||||
|
node(int a=0,int b=0):v(a),d(b){}
|
||||||
|
bool operator < (const node &a) const
|
||||||
|
{
|
||||||
|
return d>a.d;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
struct edge
|
||||||
|
{
|
||||||
|
int v,cost;
|
||||||
|
edge(int a=0,int b=0):v(a),cost(b){}
|
||||||
|
};
|
||||||
|
vector<edge> eg[maxn];
|
||||||
|
bool vis[maxn];
|
||||||
|
int n,m,s,a,b,t,c,dis[maxn],ss[maxn],tt[maxn];
|
||||||
|
void dijkstra(int x)
|
||||||
|
{
|
||||||
|
memset(vis,false,sizeof(vis));
|
||||||
|
for(int i=0; i<=n; i++)
|
||||||
|
dis[i]=inf;
|
||||||
|
priority_queue<node>q;
|
||||||
|
while(!q.empty()) q.pop();
|
||||||
|
dis[x]=0;
|
||||||
|
q.push(node(x,0));
|
||||||
|
node tmp;
|
||||||
|
while(!q.empty())
|
||||||
|
{
|
||||||
|
tmp=q.top();
|
||||||
|
q.pop();
|
||||||
|
int u=tmp.v;
|
||||||
|
if(vis[u]) continue;
|
||||||
|
vis[u]=true;
|
||||||
|
for(int i=0; i<eg[u].size(); i++)
|
||||||
|
{
|
||||||
|
int v=eg[tmp.v][i].v;
|
||||||
|
int cost=eg[u][i].cost;
|
||||||
|
if(!vis[v]&&dis[v]>dis[u]+cost)
|
||||||
|
{
|
||||||
|
dis[v]=dis[u]+cost;
|
||||||
|
q.push(node(v,dis[v]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
//freopen("in.txt","r",stdin);
|
||||||
|
while(~scanf("%d%d%d%d",&n,&m,&s,&t)&&n)
|
||||||
|
{
|
||||||
|
for(int i=1;i<=n;i++)
|
||||||
|
eg[i].clear();
|
||||||
|
while(m--)
|
||||||
|
{
|
||||||
|
scanf("%d%d%d",&a,&b,&c);
|
||||||
|
eg[a].push_back(edge(b,c));
|
||||||
|
eg[b].push_back(edge(a,c));
|
||||||
|
}
|
||||||
|
for(int i=1;i<=s;i++)
|
||||||
|
scanf("%d",&ss[i]);
|
||||||
|
for(int i=1;i<=t;i++)
|
||||||
|
scanf("%d",&tt[i]);
|
||||||
|
int ans=inf;
|
||||||
|
for(int i=1;i<=s;i++)
|
||||||
|
{
|
||||||
|
dijkstra(ss[i]);
|
||||||
|
for(int j=1;j<=t;j++)
|
||||||
|
ans=min(ans,dis[tt[j]]);
|
||||||
|
}
|
||||||
|
if(ans!=inf) printf("%d\n",ans);
|
||||||
|
else printf("What a pity!\n");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
50
SDUSTOJ/1800_cnblogs.cpp
Normal file
50
SDUSTOJ/1800_cnblogs.cpp
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
/* ***********************************************
|
||||||
|
Author :devil
|
||||||
|
Created Time :2016/4/26 21:58:52
|
||||||
|
************************************************ */
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstring>
|
||||||
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <vector>
|
||||||
|
#include <queue>
|
||||||
|
#include <set>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
#include <cmath>
|
||||||
|
#include <stdlib.h>
|
||||||
|
using namespace std;
|
||||||
|
const int N=1010;
|
||||||
|
int dp[N],a[N],b[N],c[N];
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
//freopen("in.txt","r",stdin);
|
||||||
|
int t,n;
|
||||||
|
scanf("%d",&t);
|
||||||
|
while(t--)
|
||||||
|
{
|
||||||
|
scanf("%d",&n);
|
||||||
|
for(int i=1; i<=n; i++)
|
||||||
|
scanf("%d",&a[i]);
|
||||||
|
int ma=0;
|
||||||
|
memset(c,0,sizeof(c));
|
||||||
|
c[1]=n;
|
||||||
|
for(int i=1; i<=n; i++)
|
||||||
|
{
|
||||||
|
b[i]=dp[i]=1;
|
||||||
|
for(int j=1; j<i; j++)
|
||||||
|
{
|
||||||
|
if(a[i]>a[j]&&dp[i]<dp[j]+1)
|
||||||
|
{
|
||||||
|
dp[i]=dp[j]+1;
|
||||||
|
b[i]=b[j];
|
||||||
|
}
|
||||||
|
else if(a[i]>a[j]&&dp[i]==dp[j]+1) b[i]+=b[j];
|
||||||
|
}
|
||||||
|
if(dp[i]>1) c[dp[i]]+=b[i];
|
||||||
|
ma=max(ma,dp[i]);
|
||||||
|
}
|
||||||
|
printf("%d\n",c[ma]);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
62
SDUSTOJ/1801_cnblogs.cpp
Normal file
62
SDUSTOJ/1801_cnblogs.cpp
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
/* ***********************************************
|
||||||
|
Author :devil
|
||||||
|
Created Time :2016/4/26 22:18:57
|
||||||
|
************************************************ */
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstring>
|
||||||
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <vector>
|
||||||
|
#include <queue>
|
||||||
|
#include <set>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
#include <cmath>
|
||||||
|
#include <stdlib.h>
|
||||||
|
using namespace std;
|
||||||
|
typedef long long LL;
|
||||||
|
const int N=110;
|
||||||
|
const int mod=1e9+9;
|
||||||
|
LL dp[N][N],dp2[N][N];
|
||||||
|
int a[N],b[N];
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
//freopen("in.txt","r",stdin);
|
||||||
|
int t,n,m;
|
||||||
|
scanf("%d",&t);
|
||||||
|
while(t--)
|
||||||
|
{
|
||||||
|
scanf("%d%d",&n,&m);
|
||||||
|
for(int i=1; i<=n; i++)
|
||||||
|
scanf("%d",&a[i]);
|
||||||
|
memset(dp,0,sizeof(dp));
|
||||||
|
memset(dp2,0,sizeof(dp2));
|
||||||
|
memset(b,-1,sizeof(b));
|
||||||
|
b[a[1]]=dp[a[1]][1]=1;
|
||||||
|
for(int i=2;i<=n;i++)
|
||||||
|
{
|
||||||
|
dp[a[i]][1]=1;
|
||||||
|
int mi=min(i,m);
|
||||||
|
for(int k=2;k<=mi;k++)
|
||||||
|
{
|
||||||
|
for(int j=1;j<a[i];j++)
|
||||||
|
{
|
||||||
|
dp[a[i]][k]+=dp[j][k-1];
|
||||||
|
if(dp[a[i]][k]>=mod) dp[a[i]][k]-=mod;
|
||||||
|
}
|
||||||
|
if(b[a[i]]!=-1)
|
||||||
|
{
|
||||||
|
dp[a[i]][k]-=dp2[a[i]][k];
|
||||||
|
if(dp[a[i]][k]<0) dp[a[i]][k]+=mod;
|
||||||
|
}
|
||||||
|
dp2[a[i]][k]=dp[a[i]][k];
|
||||||
|
}
|
||||||
|
b[a[i]]=i;
|
||||||
|
}
|
||||||
|
LL ans=0;
|
||||||
|
for(int i=1;i<=n;i++)
|
||||||
|
ans=(ans+dp[i][m])%mod;
|
||||||
|
printf("%lld\n",ans);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
69
SDUSTOJ/1802.cpp
Normal file
69
SDUSTOJ/1802.cpp
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
using namespace std;
|
||||||
|
/*
|
||||||
|
bool check(int inc)
|
||||||
|
{
|
||||||
|
if(inc%36!=0) return false;
|
||||||
|
char buff[32];
|
||||||
|
memset(buff,0,32);
|
||||||
|
sprintf(buff,"%d",inc);
|
||||||
|
if(strstr(buff,"36")==NULL) return false;
|
||||||
|
int len=strlen(buff);
|
||||||
|
for(int i=0;i<len;i++)
|
||||||
|
{
|
||||||
|
if(buff[i]=='3')
|
||||||
|
{
|
||||||
|
if(buff[i+1]!='6') return false;
|
||||||
|
}
|
||||||
|
if(buff[i]=='6')
|
||||||
|
{
|
||||||
|
if(i==0) return false;
|
||||||
|
else if(buff[i-1]!='3') return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cnt=0;
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
freopen("aaa.txt","w",stdout);
|
||||||
|
for(int i=1;i<=100000;i++)
|
||||||
|
{
|
||||||
|
if(check(i)) {
|
||||||
|
cnt++;printf("%d,",i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("#%d",cnt);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
int num[119]={36,360,936,1368,1836,2736,3600,3636,3672,4536,5364,5436,7236,8136,9036,9360,9936,10368,10836,11736,13608,13644,13680,14364,14436,17136,18036,18360,18936,19368,19836,20736,22536,23652,23688,25236,27036,27360,27936,28368,28836,29736,36000,36036,36072,36108,36144,36180,36252,36288,36360,36504,36540,36720,36792,36828,36900,36936,36972,40536,41364,41436,44136,45036,45360,45936,47736,49536,50364,50436,52236,53604,53640,54036,54360,54936,55368,55836,58536,59364,59436,70236,71136,72036,72360,72936,73620,73692,74736,77364,77436,79236,80136,81036,81360,81936,82368,82836,83628,85536,88236,89136,90036,90360,90936,91368,91836,92736,93600,93636,93672,94536,95364,95436,97236,98136,99036,99360,99936};
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int T;
|
||||||
|
scanf("%d",&T);
|
||||||
|
for(int i=0;i<T;i++)
|
||||||
|
{
|
||||||
|
int L;
|
||||||
|
scanf("%d",&L);
|
||||||
|
bool found=false;
|
||||||
|
for(int k=0;k<119;k++)
|
||||||
|
{
|
||||||
|
if(num[k]<L) continue;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("%d\n",num[k]);
|
||||||
|
found=true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!found)
|
||||||
|
{
|
||||||
|
printf("-1\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
2
SDUSTOJ/Readme.md
Normal file
2
SDUSTOJ/Readme.md
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
#山东科技大学 SDUSTOJ
|
||||||
|
[Goto SDUSTOJ Home Page (May be changed since last update)](http://acm.zning.net/JudgeOnline/ "Welcome to SDUSTOJ")
|
59
TYVJ/1403.cpp
Normal file
59
TYVJ/1403.cpp
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
#include <algorithm>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
#define MAXM 100000
|
||||||
|
#define MAXN 20000
|
||||||
|
struct ppk
|
||||||
|
{
|
||||||
|
int a,b,c;
|
||||||
|
};
|
||||||
|
bool cmp(const ppk& a,const ppk& b)
|
||||||
|
{
|
||||||
|
return a.c>b.c;
|
||||||
|
}
|
||||||
|
int f[MAXN*2];
|
||||||
|
ppk X[MAXM];
|
||||||
|
|
||||||
|
int get(int x)
|
||||||
|
{
|
||||||
|
if(x==f[x]) return x;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
f[x]=get(f[x]);
|
||||||
|
return f[x];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int n,m;
|
||||||
|
scanf("%d %d",&n,&m);
|
||||||
|
for(int i=1;i<=n*2;i++)
|
||||||
|
{
|
||||||
|
f[i]=i;
|
||||||
|
}
|
||||||
|
for(int i=0;i<m;i++)
|
||||||
|
{
|
||||||
|
scanf("%d %d %d",&X[i].a,&X[i].b,&X[i].c);
|
||||||
|
}
|
||||||
|
sort(X,X+m,cmp);
|
||||||
|
for(int s=0;s<m;s++)
|
||||||
|
{
|
||||||
|
int x=get(X[s].a);
|
||||||
|
int y=get(X[s].b);
|
||||||
|
if(x==y)
|
||||||
|
{
|
||||||
|
printf("%d\n",X[s].c);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int w=get(X[s].a+n);
|
||||||
|
int t=get(X[s].b+n);
|
||||||
|
f[x]=t;
|
||||||
|
f[y]=w;
|
||||||
|
}
|
||||||
|
printf("0\n");
|
||||||
|
return 0;
|
||||||
|
}
|
74
TYVJ/1403_chinaunix.cpp
Normal file
74
TYVJ/1403_chinaunix.cpp
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstring>
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
const int M = 100000;
|
||||||
|
const int N = 20000;
|
||||||
|
|
||||||
|
struct EDGE {
|
||||||
|
int a;
|
||||||
|
int b;
|
||||||
|
int v;
|
||||||
|
} edge[M];
|
||||||
|
|
||||||
|
int f[N * 2];
|
||||||
|
|
||||||
|
bool Compare(const EDGE &a, const EDGE &b)
|
||||||
|
{
|
||||||
|
return a.v < b.v;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Find(int x)
|
||||||
|
{
|
||||||
|
if (f[x] == x) {
|
||||||
|
return f[x];
|
||||||
|
} else {
|
||||||
|
return f[x] = Find(f[x]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int n, m;
|
||||||
|
|
||||||
|
ios::sync_with_stdio(false);
|
||||||
|
|
||||||
|
cin >> n;
|
||||||
|
cin >> m;
|
||||||
|
for (int i = 0; i < m; i++) {
|
||||||
|
cin >> edge[i].a;
|
||||||
|
cin >> edge[i].b;
|
||||||
|
cin >> edge[i].v;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < n * 2; i++) {
|
||||||
|
f[i] = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
sort(edge, edge + m, Compare);
|
||||||
|
|
||||||
|
for (int i = m - 1; i >= 0; i--) {
|
||||||
|
int x = Find(edge[i].a);
|
||||||
|
int y = Find(edge[i].b);
|
||||||
|
|
||||||
|
if (x == y) {
|
||||||
|
cout << edge[i].v << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int xx = Find(edge[i].a + n);
|
||||||
|
int yy = Find(edge[i].b + n);
|
||||||
|
|
||||||
|
f[x] = yy;
|
||||||
|
f[y] = xx;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "0" << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
40
TYVJ/1403_hzwer.cpp
Normal file
40
TYVJ/1403_hzwer.cpp
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
#include <algorithm>
|
||||||
|
#include <iostream>
|
||||||
|
using namespace std;
|
||||||
|
int n,m,f[40001],x,y;
|
||||||
|
struct data
|
||||||
|
{
|
||||||
|
int a,b,c;
|
||||||
|
}e[100001];
|
||||||
|
int gz(const data &a,const data &b)
|
||||||
|
{
|
||||||
|
if(a.c>b.c)return 1;
|
||||||
|
else return 0;
|
||||||
|
}
|
||||||
|
int find(int x)
|
||||||
|
{
|
||||||
|
return f[x]==x?x:f[x]=find(f[x]);
|
||||||
|
}
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
cin>>n>>m;
|
||||||
|
for(int i=1;i<=m;i++)
|
||||||
|
cin>>e[i].a>>e[i].b>>e[i].c;
|
||||||
|
for(int i=1;i<=n*2;i++)
|
||||||
|
f[i]=i;
|
||||||
|
sort(e+1,e+m+1,gz);
|
||||||
|
for(int i=1;i<=m;i++)
|
||||||
|
{
|
||||||
|
x=find(e[i].a);
|
||||||
|
y=find(e[i].b);
|
||||||
|
if(x==y)
|
||||||
|
{
|
||||||
|
cout<<e[i].c;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
f[y] = find(e[i].a + n);
|
||||||
|
f[x] = find(e[i].b + n);
|
||||||
|
}
|
||||||
|
cout<<0;
|
||||||
|
return 0;
|
||||||
|
}
|
2
TYVJ/Readme.md
Normal file
2
TYVJ/Readme.md
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
#太原成成中学 TYVJ
|
||||||
|
[Goto Home Page](http://www.tyvj.cn/ "Welcome to TYVJ 4.0")
|
Loading…
Reference in New Issue
Block a user